Skip to content

Commit e98741c

Browse files
bearomorphismLee-W
authored andcommitted
refactor(cmd): unnest try except
1 parent 478624e commit e98741c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

commitizen/cmd.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ def _try_decode(bytes_: bytes) -> str:
2222
try:
2323
return bytes_.decode("utf-8")
2424
except UnicodeDecodeError:
25-
charset_match = from_bytes(bytes_).best()
26-
if charset_match is None:
27-
raise CharacterSetDecodeError()
28-
try:
29-
return bytes_.decode(charset_match.encoding)
30-
except UnicodeDecodeError as e:
31-
raise CharacterSetDecodeError() from e
25+
pass
26+
27+
charset_match = from_bytes(bytes_).best()
28+
if charset_match is None:
29+
raise CharacterSetDecodeError()
30+
try:
31+
return bytes_.decode(charset_match.encoding)
32+
except UnicodeDecodeError as e:
33+
raise CharacterSetDecodeError() from e
3234

3335

3436
def run(cmd: str, env: Mapping[str, str] | None = None) -> Command:

0 commit comments

Comments
 (0)