Skip to content

Commit 6d77b4a

Browse files
chuenchen309claude
andauthored
fix(integrations): catch OverflowError on a priority: .inf in add/remove (#3589)
IntegrationCatalog.add_catalog and remove_catalog re-validate the existing catalog entries' priorities inline, separately from the base loader. Both did `int(raw_priority)` under `except (TypeError, ValueError)`, so a `priority: .inf` (float('inf')) raised OverflowError: add_catalog leaked a raw traceback instead of IntegrationValidationError, and remove_catalog crashed while building the display order. Add OverflowError to both handlers, matching the base loader (#3525) and the workflow/step loaders (#3526). add_catalog now raises IntegrationValidationError; remove_catalog falls back to positional order like the other non-integer priorities. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 57cc518 commit 6d77b4a

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

src/specify_cli/integrations/catalog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ def add_catalog(self, url: str, name: Optional[str] = None) -> None:
429429
)
430430
try:
431431
normalized_priority = int(raw_priority)
432-
except (TypeError, ValueError):
432+
except (TypeError, ValueError, OverflowError):
433+
# OverflowError: int(float("inf")) — a ``priority: .inf``.
433434
raise IntegrationValidationError(
434435
f"Invalid catalog entry at index {idx} in {config_path}: "
435436
f"'priority' must be an integer, got "
@@ -537,7 +538,8 @@ def _is_removable_catalog_entry(item: Any) -> bool:
537538
else:
538539
try:
539540
priority = int(raw_priority)
540-
except (TypeError, ValueError):
541+
except (TypeError, ValueError, OverflowError):
542+
# OverflowError: int(float("inf")) — a ``priority: .inf``.
541543
priority = yaml_idx + 1
542544
priority_pairs.append((priority, yaml_idx))
543545
if not priority_pairs:

tests/integrations/test_integration_catalog.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,57 @@ def test_add_catalog_rejects_non_mapping_entry_with_config_path(
922922
assert str(cfg_path) in message
923923
assert "expected a mapping" in message
924924

925+
def test_add_catalog_rejects_inf_priority_in_existing_entry(
926+
self, tmp_path, monkeypatch
927+
):
928+
# ``priority: .inf`` loads as float('inf'); int() on it raises
929+
# OverflowError, which used to escape the IntegrationValidationError
930+
# contract as a raw traceback (github/spec-kit#3526 fixed the sibling
931+
# workflow/step loaders the same way).
932+
self._isolate(tmp_path, monkeypatch)
933+
cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
934+
cfg_path.write_text(
935+
yaml.dump(
936+
{
937+
"catalogs": [
938+
{
939+
"url": "https://a.example.com/catalog.json",
940+
"priority": float("inf"),
941+
}
942+
]
943+
}
944+
),
945+
encoding="utf-8",
946+
)
947+
cat = IntegrationCatalog(tmp_path)
948+
with pytest.raises(
949+
IntegrationValidationError, match="must be an integer"
950+
):
951+
cat.add_catalog("https://new.example.com/catalog.json")
952+
953+
def test_remove_catalog_tolerates_inf_priority(self, tmp_path, monkeypatch):
954+
# Building the remove display order must not crash on a ``priority:
955+
# .inf`` entry; it falls back to positional order like the other
956+
# non-integer priorities do.
957+
self._isolate(tmp_path, monkeypatch)
958+
cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
959+
cfg_path.write_text(
960+
yaml.dump(
961+
{
962+
"catalogs": [
963+
{
964+
"url": "https://a.example.com/catalog.json",
965+
"priority": float("inf"),
966+
},
967+
{"url": "https://b.example.com/catalog.json", "priority": 2},
968+
]
969+
}
970+
),
971+
encoding="utf-8",
972+
)
973+
cat = IntegrationCatalog(tmp_path)
974+
cat.remove_catalog(0) # must not raise OverflowError
975+
925976
def test_add_catalog_skips_blank_url_entries(self, tmp_path, monkeypatch):
926977
self._isolate(tmp_path, monkeypatch)
927978
cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"

0 commit comments

Comments
 (0)