зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1646406 - Distinguish between user errors and actual reportable exceptions in `mach` r=mhentges,froydnj
Add a new `UserError` class which when thrown doesn't get reported to Sentry. Differential Revision: https://phabricator.services.mozilla.com/D85026
This commit is contained in:
Родитель
9b4ff5144e
Коммит
ffd5064859
|
@ -37,7 +37,7 @@ from .dispatcher import CommandAction
|
|||
from .logging import LoggingManager
|
||||
from .registrar import Registrar
|
||||
from .sentry import register_sentry, NoopErrorReporter
|
||||
from .util import setenv
|
||||
from .util import setenv, UserError
|
||||
|
||||
SUGGEST_MACH_BUSTED_TEMPLATE = r'''
|
||||
You can invoke |./mach busted| to check if this issue is already on file. If it
|
||||
|
@ -58,6 +58,10 @@ message.
|
|||
The details of the failure are as follows:
|
||||
'''.lstrip()
|
||||
|
||||
USER_ERROR = r'''
|
||||
This is a user error and does not appear to be a bug in mach.
|
||||
'''.lstrip()
|
||||
|
||||
COMMAND_ERROR_TEMPLATE = r'''
|
||||
The error occurred in the implementation of the invoked mach command.
|
||||
|
||||
|
@ -483,6 +487,15 @@ To see more help for a specific command, run:
|
|||
except FailedCommandError as e:
|
||||
print(e.message)
|
||||
return e.exit_code
|
||||
except UserError:
|
||||
# We explicitly don't report UserErrors to Sentry.
|
||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||
# The first two frames are us and are never used.
|
||||
stack = traceback.extract_tb(exc_tb)[2:]
|
||||
self._print_error_header(argv, sys.stdout)
|
||||
print(USER_ERROR)
|
||||
self._print_exception(sys.stdout, exc_type, exc_value, stack)
|
||||
return 1
|
||||
except Exception:
|
||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||
sentry.report_exception(exc_value)
|
||||
|
|
|
@ -10,6 +10,13 @@ import sys
|
|||
from six import text_type
|
||||
|
||||
|
||||
class UserError(Exception):
|
||||
"""Represents an error caused by something the user did wrong rather than
|
||||
an internal `mach` failure. Exceptions that are subclasses of this class
|
||||
will not be reported as failures to Sentry.
|
||||
"""
|
||||
|
||||
|
||||
def setenv(key, value):
|
||||
"""Compatibility shim to ensure the proper string type is used with
|
||||
os.environ for the version of Python being used.
|
||||
|
|
Загрузка…
Ссылка в новой задаче