File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 243243
244244def commitizen_excepthook (type , value , tracekback ):
245245 if isinstance (value , CommitizenException ):
246+ if value .message :
247+ value .output_method (value .message )
246248 sys .exit (value .exit_code )
247249 else :
248250 original_excepthook (type , value , tracekback )
Original file line number Diff line number Diff line change @@ -26,7 +26,18 @@ class ExitCode(enum.IntEnum):
2626
2727
2828class 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
3041
3142
3243class ExpectedExit (CommitizenException ):
@@ -43,18 +54,12 @@ class NoCommitizenFoundException(CommitizenException):
4354
4455class NotAGitProjectError (CommitizenException ):
4556 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"
5158
5259
5360class MissingConfigError (CommitizenException ):
5461 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."
5863
5964
6065class NoCommitsFoundError (CommitizenException ):
You can’t perform that action at this time.
0 commit comments