Skip to content

Commit e5d4f63

Browse files
Copilotmnriem
andcommitted
fix: wrap _load_catalog_config() calls in catalog_list with try/except
- Check SPECKIT_CATALOG_URL first (matching get_active_catalogs() resolution order) - Wrap both _load_catalog_config() calls in try/except ValidationError so a malformed config file cannot crash `specify extension catalog list` after the active catalogs have already been printed successfully Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent 990a151 commit e5d4f63

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,17 +1881,27 @@ def catalog_list():
18811881

18821882
config_path = project_root / ".specify" / "extension-catalogs.yml"
18831883
user_config_path = Path.home() / ".specify" / "extension-catalogs.yml"
1884-
if config_path.exists() and catalog._load_catalog_config(config_path) is not None:
1885-
console.print(f"[dim]Config: {config_path.relative_to(project_root)}[/dim]")
1886-
elif os.environ.get("SPECKIT_CATALOG_URL"):
1884+
if os.environ.get("SPECKIT_CATALOG_URL"):
18871885
console.print("[dim]Catalog configured via SPECKIT_CATALOG_URL environment variable.[/dim]")
1888-
elif user_config_path.exists() and catalog._load_catalog_config(user_config_path) is not None:
1889-
console.print("[dim]Config: ~/.specify/extension-catalogs.yml[/dim]")
18901886
else:
1891-
console.print("[dim]Using built-in default catalog stack.[/dim]")
1892-
console.print(
1893-
"[dim]Add .specify/extension-catalogs.yml to customize.[/dim]"
1894-
)
1887+
try:
1888+
proj_loaded = config_path.exists() and catalog._load_catalog_config(config_path) is not None
1889+
except ValidationError:
1890+
proj_loaded = False
1891+
if proj_loaded:
1892+
console.print(f"[dim]Config: {config_path.relative_to(project_root)}[/dim]")
1893+
else:
1894+
try:
1895+
user_loaded = user_config_path.exists() and catalog._load_catalog_config(user_config_path) is not None
1896+
except ValidationError:
1897+
user_loaded = False
1898+
if user_loaded:
1899+
console.print("[dim]Config: ~/.specify/extension-catalogs.yml[/dim]")
1900+
else:
1901+
console.print("[dim]Using built-in default catalog stack.[/dim]")
1902+
console.print(
1903+
"[dim]Add .specify/extension-catalogs.yml to customize.[/dim]"
1904+
)
18951905

18961906

18971907
@catalog_app.command("add")

0 commit comments

Comments
 (0)