File tree 2 files changed +16
-9
lines changed 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 243
243
244
244
def commitizen_excepthook (type , value , tracekback ):
245
245
if isinstance (value , CommitizenException ):
246
+ if value .message :
247
+ value .output_method (value .message )
246
248
sys .exit (value .exit_code )
247
249
else :
248
250
original_excepthook (type , value , tracekback )
Original file line number Diff line number Diff line change @@ -26,7 +26,18 @@ class ExitCode(enum.IntEnum):
26
26
27
27
28
28
class CommitizenException (Exception ):
29
- pass
29
+ def __init__ (self , * args , ** kwargs ):
30
+ self .output_method = kwargs .get ("output_method" ) or out .error
31
+ self .exit_code = self .__class__ .exit_code
32
+ if args :
33
+ self .message = args [0 ]
34
+ elif hasattr (self .__class__ , "message" ):
35
+ self .message = self .__class__ .message
36
+ else :
37
+ self .message = ""
38
+
39
+ def __str__ (self ):
40
+ return self .message
30
41
31
42
32
43
class ExpectedExit (CommitizenException ):
@@ -43,18 +54,12 @@ class NoCommitizenFoundException(CommitizenException):
43
54
44
55
class NotAGitProjectError (CommitizenException ):
45
56
exit_code = ExitCode .NOT_A_GIT_PROJECT
46
-
47
- def __init__ (self , * args , ** kwargs ):
48
- out .error (
49
- "fatal: not a git repository (or any of the parent directories): .git"
50
- )
57
+ message = "fatal: not a git repository (or any of the parent directories): .git"
51
58
52
59
53
60
class MissingConfigError (CommitizenException ):
54
61
exit_code = ExitCode .MISSING_CONFIG
55
-
56
- def __init__ (self , * args , ** kwargs ):
57
- out .error ("fatal: customize is not set in configuration file." )
62
+ message = "fatal: customize is not set in configuration file."
58
63
59
64
60
65
class NoCommitsFoundError (CommitizenException ):
You can’t perform that action at this time.
0 commit comments