diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-08-30 11:22:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-08-30 11:22:53 +0000 |
commit | 6cfa8e0963e9a518a25528a248932fcf41b4f969 (patch) | |
tree | 6882a2a7a3214ef85d7a946f2506e9ed2c3f60f5 /pre_commit/error_handler.py | |
parent | Adding upstream version 2.6.0. (diff) | |
download | pre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.tar.xz pre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.zip |
Adding upstream version 2.7.1.upstream/2.7.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/error_handler.py')
-rw-r--r-- | pre_commit/error_handler.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pre_commit/error_handler.py b/pre_commit/error_handler.py index b2321ae..13d78cb 100644 --- a/pre_commit/error_handler.py +++ b/pre_commit/error_handler.py @@ -18,10 +18,17 @@ class FatalError(RuntimeError): def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None: error_msg = f'{msg}: {type(exc).__name__}: '.encode() + force_bytes(exc) output.write_line_b(error_msg) - log_path = os.path.join(Store().directory, 'pre-commit.log') - output.write_line(f'Check the log at {log_path}') - with open(log_path, 'wb') as log: + storedir = Store().directory + log_path = os.path.join(storedir, 'pre-commit.log') + with contextlib.ExitStack() as ctx: + if os.access(storedir, os.W_OK): + output.write_line(f'Check the log at {log_path}') + log = ctx.enter_context(open(log_path, 'wb')) + else: # pragma: win32 no cover + output.write_line(f'Failed to write to log at {log_path}') + log = sys.stdout.buffer + _log_line = functools.partial(output.write_line, stream=log) _log_line_b = functools.partial(output.write_line_b, stream=log) |