Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
56 lines (45 loc) · 1.36 KB

File metadata and controls

56 lines (45 loc) · 1.36 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import contextlib
import os.path
import traceback
import six
from pre_commit import five
from pre_commit import output
from pre_commit.errors import FatalError
from pre_commit.store import Store
# For testing purposes
class PreCommitSystemExit(SystemExit):
pass
def _to_bytes(exc):
try:
return bytes(exc)
except Exception:
return six.text_type(exc).encode('UTF-8')
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',
))
output.write(error_msg)
output.write_line('Check the log at ~/.pre-commit/pre-commit.log')
store = Store()
store.require_created()
with open(os.path.join(store.directory, 'pre-commit.log'), 'wb') as log:
output.write(error_msg, stream=log)
output.write_line(formatted, stream=log)
raise PreCommitSystemExit(1)
@contextlib.contextmanager
def error_handler():
try:
yield
except FatalError as e:
_log_and_exit('An error has occurred', e, traceback.format_exc())
except Exception as e:
_log_and_exit(
'An unexpected error has occurred',
e,
traceback.format_exc(),
)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.