FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pre-commit/pre_commit/error_handler.py at main · pre-commit/pre-commit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pre-commit
/
pre-commit
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
1k
Star
15.5k
Code
Issues
18
Pull requests
8
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
pre-commit
/
pre_commit
/
error_handler.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (70 loc) · 2.56 KB
Breadcrumbs
pre-commit
/
pre_commit
/
error_handler.py
Copy path
File metadata and controls
81 lines (70 loc) · 2.56 KB
Raw
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from
__future__
import
annotations
import
contextlib
import
functools
import
os
.
path
import
sys
import
traceback
from
collections
.
abc
import
Generator
from
typing
import
IO
import
pre_commit
.
constants
as
C
from
pre_commit
import
output
from
pre_commit
.
errors
import
FatalError
from
pre_commit
.
store
import
Store
from
pre_commit
.
util
import
cmd_output_b
from
pre_commit
.
util
import
force_bytes
def
_log_and_exit
(
msg
:
str
,
ret_code
:
int
,
exc
:
BaseException
,
formatted
:
str
,
)
->
None
:
error_msg
=
f'
{
msg
}
:
{
type
(
exc
).
__name__
}
: '
.
encode
()
+
force_bytes
(
exc
)
output
.
write_line_b
(
error_msg
)
_
,
git_version_b
,
_
=
cmd_output_b
(
'git'
,
'--version'
,
check
=
False
)
git_version
=
git_version_b
.
decode
(
errors
=
'backslashreplace'
).
rstrip
()
storedir
=
Store
().
directory
log_path
=
os
.
path
.
join
(
storedir
,
'pre-commit.log'
)
with
contextlib
.
ExitStack
()
as
ctx
:
if
os
.
access
(
storedir
,
os
.
W_OK
):
output
.
write_line
(
f'Check the log at
{
log_path
}
'
)
log
:
IO
[
bytes
]
=
ctx
.
enter_context
(
open
(
log_path
,
'wb'
))
else
:
# pragma: win32 no cover
output
.
write_line
(
f'Failed to write to log at
{
log_path
}
'
)
log
=
sys
.
stdout
.
buffer
_log_line
=
functools
.
partial
(
output
.
write_line
,
stream
=
log
)
_log_line_b
=
functools
.
partial
(
output
.
write_line_b
,
stream
=
log
)
_log_line
(
'### version information'
)
_log_line
()
_log_line
(
'```'
)
_log_line
(
f'pre-commit version:
{
C
.
VERSION
}
'
)
_log_line
(
f'git --version:
{
git_version
}
'
)
_log_line
(
'sys.version:'
)
for
line
in
sys
.
version
.
splitlines
():
_log_line
(
f'
{
line
}
'
)
_log_line
(
f'sys.executable:
{
sys
.
executable
}
'
)
_log_line
(
f'os.name:
{
os
.
name
}
'
)
_log_line
(
f'sys.platform:
{
sys
.
platform
}
'
)
_log_line
(
'```'
)
_log_line
()
_log_line
(
'### error information'
)
_log_line
()
_log_line
(
'```'
)
_log_line_b
(
error_msg
)
_log_line
(
'```'
)
_log_line
()
_log_line
(
'```'
)
_log_line
(
formatted
.
rstrip
())
_log_line
(
'```'
)
raise
SystemExit
(
ret_code
)
@
contextlib
.
contextmanager
def
error_handler
()
->
Generator
[
None
]:
try
:
yield
except
(
Exception
,
KeyboardInterrupt
)
as
e
:
if
isinstance
(
e
,
FatalError
):
msg
,
ret_code
=
'An error has occurred'
,
1
elif
isinstance
(
e
,
KeyboardInterrupt
):
msg
,
ret_code
=
'Interrupted (^C)'
,
130
else
:
msg
,
ret_code
=
'An unexpected error has occurred'
,
3
_log_and_exit
(
msg
,
ret_code
,
e
,
traceback
.
format_exc
())
Back
|
FazBrowse Home
|
New Git URL