fix(bundler): validate a catalog source before persisting it - #4535
Open
jawwad-ali wants to merge 1 commit into
Open
fix(bundler): validate a catalog source before persisting it#4535jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
`add_source` wrote the new entry and only then constructed it:
catalogs.append(entry)
_write(project_root, catalogs)
return CatalogSource.from_dict(entry, Scope.PROJECT)
`CatalogSource.from_dict` already rejects an empty id, but by the time it ran
the entry was on disk. A whitespace-only `--id` (or a url from which no id can
be derived) therefore reported an error while leaving a broken entry behind:
add_source -> raised: A catalog source is missing its 'id'.
AFTER : [{"id": "", "url": "https://example.test/c.json", ...}]
The user sees a failure and reasonably assumes nothing happened. In fact the
project's catalog config is now unusable -- every command that loads the stack
fails on that entry:
load_source_stack -> BROKEN: BundlerError A catalog source is missing its 'id'.
so the project stays wedged until bundle-catalogs.yml is hand-edited.
Constructing before writing reuses the validation that already exists; nothing
is persisted when it fails.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
add_sourcewrites the new entry and only then constructs it:CatalogSource.from_dictalready rejects an empty id — but by the time it runs, the entry is on disk.Reproduction on current
main(c173bf1)The command reports a failure, so the user reasonably assumes nothing happened.
It wedges the project
Every command that loads the catalog stack now fails on that stray entry:
So a single mistyped
catalog add --id " "leaves the project's catalog config unusable untilbundle-catalogs.ymlis hand-edited — by hand, for a file thebundle catalogcommands exist to manage.Fix
Construct before writing, reusing the validation that already exists rather than adding a second check that could drift:
After the fix:
Verification
upstream/main→ passing with the fix.load_source_stackstill succeeds — the latter is what the stray entry actually broke.tests/unit: 536 passed vs a clean-mainbaseline of 535 passed, same 2 pre-existing failures, none new.uvx ruff@0.15.0 check src tests→ cleanNo behaviour change for any input that previously succeeded. The reordered call is the same construction, just earlier, and it raises for exactly the input that already raised — the difference is that the failure no longer leaves a file behind.
Note on overlap: this touches
commands_impl/catalog_config.py, as does my #4533, but a different function (add_sourcevsremove_source). Happy to rebase whichever lands second.Written with assistance from Claude Code. Bug found, reproduced, and verified by me on current
main.🤖 Generated with Claude Code