Skip to content

Commit c3c9635

Browse files
committed
fix: make the scope of try except smaller
1 parent aef0171 commit c3c9635

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

commitizen/commands/init.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS
1414
from commitizen.exceptions import (
1515
InitFailedError,
16+
MissingCzCustomizeConfigError,
1617
NoAnswersError,
1718
)
1819
from commitizen.git import get_latest_tag_name, get_tag_names, smart_open
@@ -169,16 +170,16 @@ def _ask_config_path(self) -> Path:
169170

170171
def _ask_name(self) -> str:
171172
def construct_choice_with_description(cz_name: str) -> questionary.Choice:
172-
try:
173-
cz_class = registry.get(cz_name)
174-
if cz_class:
173+
cz_class = registry.get(cz_name)
174+
if cz_class:
175+
try:
175176
cz_obj = cz_class(self.config)
176-
first_example = cz_obj.schema().partition("\n")[0]
177-
return questionary.Choice(
178-
title=cz_name, value=cz_name, description=f"{first_example}"
179-
)
180-
except Exception: # pylint: disable=broad-except
181-
pass
177+
except MissingCzCustomizeConfigError:
178+
return questionary.Choice(title=cz_name, value=cz_name)
179+
first_example = cz_obj.schema().partition("\n")[0]
180+
return questionary.Choice(
181+
title=cz_name, value=cz_name, description=first_example
182+
)
182183
return questionary.Choice(title=cz_name, value=cz_name)
183184

184185
name: str = questionary.select(

0 commit comments

Comments
 (0)