mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix printing of non-ascii in error handler
This commit is contained in:
parent
6b005cff0d
commit
2463738af4
2 changed files with 38 additions and 11 deletions
|
|
@ -7,7 +7,9 @@ import io
|
|||
import os.path
|
||||
import traceback
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.output import sys_stdout_write_wrapper
|
||||
from pre_commit.store import Store
|
||||
|
||||
|
||||
|
|
@ -16,15 +18,15 @@ class PreCommitSystemExit(SystemExit):
|
|||
pass
|
||||
|
||||
|
||||
def _log_and_exit(msg, exc, formatted, print_fn=print):
|
||||
error_msg = '{0}: {1}: {2}'.format(msg, type(exc).__name__, exc)
|
||||
print_fn(error_msg)
|
||||
print_fn('Check the log at ~/.pre-commit/pre-commit.log')
|
||||
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)
|
||||
write_fn(error_msg)
|
||||
write_fn('Check the log at ~/.pre-commit/pre-commit.log\n')
|
||||
store = Store()
|
||||
store.require_created()
|
||||
with io.open(os.path.join(store.directory, 'pre-commit.log'), 'w') as log:
|
||||
log.write(error_msg + '\n')
|
||||
log.write(formatted + '\n')
|
||||
with io.open(os.path.join(store.directory, 'pre-commit.log'), 'wb') as log:
|
||||
log.write(five.to_bytes(error_msg))
|
||||
log.write(five.to_bytes(formatted) + b'\n')
|
||||
raise PreCommitSystemExit(1)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue