Fail gracefully on undecodable install output.

This commit is contained in:
Anthony Sottile
2016-01-12 09:51:40 -08:00
parent 75aaadd4c4
commit 2aaaddb5cc
9 changed files with 104 additions and 24 deletions

View File

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