File tree Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Original file line number Diff line number Diff line change @@ -583,11 +583,12 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
583
583
Receives digits and strings and outputs the parsed integer which
584
584
represents the exit code found in exceptions.
585
585
"""
586
- return [
587
- code .value
588
- for s in comma_separated_no_raise .split ("," )
589
- if (code := ExitCode .from_str (s )) is not None
590
- ]
586
+ try :
587
+ return [ExitCode .from_str (s ).value for s in comma_separated_no_raise .split ("," )]
588
+ except (KeyError , ValueError ) as e :
589
+ raise InvalidCommandArgumentError (
590
+ f"Invalid no_raise value `{ comma_separated_no_raise } `. "
591
+ ) from e
591
592
592
593
593
594
if TYPE_CHECKING :
Original file line number Diff line number Diff line change @@ -42,21 +42,10 @@ class ExitCode(IntEnum):
42
42
COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED = 32
43
43
44
44
@classmethod
45
- def from_str (cls , value : str ) -> ExitCode | None :
45
+ def from_str (cls , value : str ) -> ExitCode :
46
46
if value .isdecimal ():
47
- try :
48
- return cls (int (value ))
49
- except ValueError :
50
- out .warn (
51
- f"WARN: no_raise value `{ value } ` is not a valid exit code. Skipping."
52
- )
53
- return None
54
-
55
- try :
56
- return cls [value .strip ()]
57
- except KeyError :
58
- out .warn (f"WARN: no_raise key `{ value } ` does not exist. Skipping." )
59
- return None
47
+ return cls (int (value ))
48
+ return cls [value .strip ()]
60
49
61
50
62
51
class CommitizenException (Exception ):
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
1
3
from commitizen .exceptions import ExitCode
2
4
3
5
@@ -26,7 +28,11 @@ def test_from_str_with_whitespace():
26
28
27
29
def test_from_str_with_invalid_values ():
28
30
"""Test from_str with invalid values."""
29
- assert ExitCode .from_str ("invalid_name" ) is None
30
- assert ExitCode .from_str ("999" ) is None # Out of range decimal
31
- assert ExitCode .from_str ("" ) is None
32
- assert ExitCode .from_str (" " ) is None
31
+ with pytest .raises (KeyError ):
32
+ ExitCode .from_str ("invalid_name" )
33
+ with pytest .raises (ValueError ):
34
+ ExitCode .from_str ("999" ) # Out of range decimal
35
+ with pytest .raises (KeyError ):
36
+ ExitCode .from_str ("" )
37
+ with pytest .raises (KeyError ):
38
+ ExitCode .from_str (" " )
You can’t perform that action at this time.
0 commit comments