mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Fail gracefully on undecodable install output.
This commit is contained in:
@@ -18,8 +18,19 @@ class PreCommitSystemExit(SystemExit):
|
||||
pass
|
||||
|
||||
|
||||
def _to_bytes(exc):
|
||||
try:
|
||||
return bytes(exc)
|
||||
except Exception:
|
||||
return five.text(exc).encode('UTF-8')
|
||||
|
||||
|
||||
def _log_and_exit(msg, exc, formatted, write_fn=sys_stdout_write_wrapper):
|
||||
error_msg = '{0}: {1}: {2}\n'.format(msg, type(exc).__name__, exc)
|
||||
error_msg = b''.join((
|
||||
five.to_bytes(msg), b': ',
|
||||
five.to_bytes(type(exc).__name__), b': ',
|
||||
_to_bytes(exc), b'\n',
|
||||
))
|
||||
write_fn(error_msg)
|
||||
write_fn('Check the log at ~/.pre-commit/pre-commit.log\n')
|
||||
store = Store()
|
||||
|
||||
Reference in New Issue
Block a user