diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-11-03 06:17:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-11-03 06:17:33 +0000 |
commit | 22b6d3abcec9046e294d08c741aa7b6338984e84 (patch) | |
tree | a0a9c823a7d82771ffb8a8b39f7143d5ba2f6b30 /pre_commit/error_handler.py | |
parent | Adding upstream version 2.7.1. (diff) | |
download | pre-commit-22b6d3abcec9046e294d08c741aa7b6338984e84.tar.xz pre-commit-22b6d3abcec9046e294d08c741aa7b6338984e84.zip |
Adding upstream version 2.8.2.upstream/2.8.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | pre_commit/error_handler.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/pre_commit/error_handler.py b/pre_commit/error_handler.py index 13d78cb..023dd35 100644 --- a/pre_commit/error_handler.py +++ b/pre_commit/error_handler.py @@ -7,15 +7,17 @@ from typing import Generator import pre_commit.constants as C from pre_commit import output +from pre_commit.errors import FatalError from pre_commit.store import Store from pre_commit.util import force_bytes -class FatalError(RuntimeError): - pass - - -def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None: +def _log_and_exit( + msg: str, + ret_code: int, + exc: BaseException, + formatted: str, +) -> None: error_msg = f'{msg}: {type(exc).__name__}: '.encode() + force_bytes(exc) output.write_line_b(error_msg) @@ -52,9 +54,9 @@ def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None: _log_line('```') _log_line() _log_line('```') - _log_line(formatted) + _log_line(formatted.rstrip()) _log_line('```') - raise SystemExit(1) + raise SystemExit(ret_code) @contextlib.contextmanager @@ -63,9 +65,9 @@ def error_handler() -> Generator[None, None, None]: yield except (Exception, KeyboardInterrupt) as e: if isinstance(e, FatalError): - msg = 'An error has occurred' + msg, ret_code = 'An error has occurred', 1 elif isinstance(e, KeyboardInterrupt): - msg = 'Interrupted (^C)' + msg, ret_code = 'Interrupted (^C)', 130 else: - msg = 'An unexpected error has occurred' - _log_and_exit(msg, e, traceback.format_exc()) + msg, ret_code = 'An unexpected error has occurred', 3 + _log_and_exit(msg, ret_code, e, traceback.format_exc()) |