diff --git a/src/specify_cli/workflows/_commands.py b/src/specify_cli/workflows/_commands.py index 95dff473b..975488bfb 100644 --- a/src/specify_cli/workflows/_commands.py +++ b/src/specify_cli/workflows/_commands.py @@ -582,6 +582,9 @@ def workflow_list(): console.print("\n[bold cyan]Installed Workflows:[/bold cyan]\n") for wf_id, wf_data in installed.items(): + if not isinstance(wf_data, dict): + console.print(f" [yellow]Warning:[/yellow] Skipping corrupted registry entry '{wf_id}'.\n") + continue marker = "" if wf_data.get("enabled", True) else " [red]\\[disabled][/red]" console.print(f" [bold]{wf_data.get('name', wf_id)}[/bold] ({wf_id}) v{wf_data.get('version', '?')}{marker}") desc = wf_data.get("description", "") @@ -866,6 +869,8 @@ def _install_workflow_from_catalog( ) raise typer.Exit(1) workflow_file.write_bytes(response.read()) + except typer.Exit: + raise except Exception as exc: if workflow_dir.exists(): import shutil diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 85b53810e..e1613563c 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -7490,6 +7490,33 @@ steps: assert result.exit_code == 0, result.output assert "corrupted" in result.output + def test_list_skips_corrupted_registry_entry(self, project_dir, monkeypatch): + import json + from typer.testing import CliRunner + from specify_cli import app + from specify_cli.workflows.catalog import WorkflowRegistry + + monkeypatch.chdir(project_dir) + registry_path = WorkflowRegistry(project_dir).registry_path + registry_path.parent.mkdir(parents=True, exist_ok=True) + registry_path.write_text( + json.dumps( + { + "schema_version": "1.0", + "workflows": { + "broken": "not-a-dict", + "ok": {"name": "OK Workflow", "version": "1.0.0"}, + }, + } + ), + encoding="utf-8", + ) + runner = CliRunner() + result = runner.invoke(app, ["workflow", "list"]) + assert result.exit_code == 0, result.output + assert "corrupted" in result.output + assert "OK Workflow" in result.output + def test_enable_disable_corrupted_registry_entry_errors(self, project_dir, monkeypatch): import json from typer.testing import CliRunner