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]:
583583 Receives digits and strings and outputs the parsed integer which
584584 represents the exit code found in exceptions.
585585 """
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
591592
592593
593594if TYPE_CHECKING :
Original file line number Diff line number Diff line change @@ -42,21 +42,10 @@ class ExitCode(IntEnum):
4242 COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED = 32
4343
4444 @classmethod
45- def from_str (cls , value : str ) -> ExitCode | None :
45+ def from_str (cls , value : str ) -> ExitCode :
4646 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 ()]
6049
6150
6251class CommitizenException (Exception ):
Original file line number Diff line number Diff line change 1+ import pytest
2+
13from commitizen .exceptions import ExitCode
24
35
@@ -26,7 +28,11 @@ def test_from_str_with_whitespace():
2628
2729def test_from_str_with_invalid_values ():
2830 """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