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
6 changes: 4 additions & 2 deletions src/specify_cli/workflows/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,14 @@ def remove_catalog(self, index: int) -> str:
raise WorkflowValidationError("No catalog config file found.")

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, UnicodeDecodeError) as exc:
raise WorkflowValidationError(
f"Catalog config file is unreadable or malformed: {exc}"
) from exc
if not isinstance(data, dict):
if data is None:
data = {}
elif not isinstance(data, dict):
raise WorkflowValidationError(
"Catalog config file is corrupted (expected a mapping)."
)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -8148,6 +8148,18 @@ def test_remove_catalog_invalid_index(self, project_dir):
with pytest.raises(WorkflowValidationError, match="out of range"):
catalog.remove_catalog(5)

@pytest.mark.parametrize("bad", [[], False, 0, ""])
def test_remove_catalog_rejects_falsy_non_mapping_config(
self, project_dir, bad
):
from specify_cli.workflows.catalog import WorkflowCatalog, WorkflowValidationError

config_path = project_dir / ".specify" / "workflow-catalogs.yml"
config_path.write_text(yaml.safe_dump(bad), encoding="utf-8")

with pytest.raises(WorkflowValidationError, match="expected a mapping"):
WorkflowCatalog(project_dir).remove_catalog(0)

def test_get_catalog_configs(self, project_dir):
from specify_cli.workflows.catalog import WorkflowCatalog

Expand Down