mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Reorganize output writing
This commit is contained in:
parent
1adfa24124
commit
0dda19f691
20 changed files with 202 additions and 142 deletions
|
|
@ -8,8 +8,8 @@ import os.path
|
|||
import traceback
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit import output
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.output import sys_stdout_write_wrapper
|
||||
from pre_commit.store import Store
|
||||
|
||||
|
||||
|
|
@ -25,19 +25,19 @@ def _to_bytes(exc):
|
|||
return five.text(exc).encode('UTF-8')
|
||||
|
||||
|
||||
def _log_and_exit(msg, exc, formatted, write_fn=sys_stdout_write_wrapper):
|
||||
def _log_and_exit(msg, exc, formatted):
|
||||
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')
|
||||
output.write(error_msg)
|
||||
output.write_line('Check the log at ~/.pre-commit/pre-commit.log')
|
||||
store = Store()
|
||||
store.require_created()
|
||||
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')
|
||||
output.write(error_msg, stream=log)
|
||||
output.write_line(formatted, stream=log)
|
||||
raise PreCommitSystemExit(1)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue