Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/specify_cli/presets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4276,11 +4276,13 @@ def _load_catalog_config(self, config_path: Path) -> Optional[List[PresetCatalog
if not config_path.exists():
return None
try:
data = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
except (yaml.YAMLError, OSError, UnicodeError) as e:
raise PresetValidationError(
f"Failed to read catalog config {config_path}: {e}"
)
if data is None:
return None
if not isinstance(data, dict):
raise PresetValidationError(
f"Invalid catalog config {config_path}: expected a mapping at root, got {type(data).__name__}"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,17 @@ def test_load_catalog_config_empty(self, project_dir):
result = catalog._load_catalog_config(config_path)
assert result is None

@pytest.mark.parametrize("bad", [[], False, 0, ""])
def test_load_catalog_config_rejects_falsy_non_mapping_root(
self, project_dir, bad
):
config_path = project_dir / ".specify" / "preset-catalogs.yml"
config_path.write_text(yaml.safe_dump(bad), encoding="utf-8")

catalog = PresetCatalog(project_dir)
with pytest.raises(PresetValidationError, match="expected a mapping"):
catalog._load_catalog_config(config_path)

def test_load_catalog_config_invalid_yaml(self, project_dir):
"""Test loading invalid YAML raises error."""
config_path = project_dir / ".specify" / "preset-catalogs.yml"
Expand Down