1
0
Fork 0

Merging upstream version 2.8.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:22:33 +01:00
parent 6ea1883b99
commit da7a7a571b
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
65 changed files with 1119 additions and 189 deletions

View file

@ -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())