Repository navigation
fix(cli): report invalid JSON config files as a usage error - #635
Merged
Merged
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
barisa-cloudsmith
approved these changes
Nov 21, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the changes that turn invalid JSON config files into clear CLI usage errors.
No open issues 🎉
What changed in this PR
This PR replaces unhandled JSON config-file errors with clear CLI usage errors across repository, upstream, and policy commands.
Changes:
- Adds a shared loader that rejects malformed JSON, decoding errors, and non-object documents with
click.BadParameter. - Updates all 10 affected command handlers to use the loader.
- Adds 40 regression cases checking usage errors and preventing API calls, plus a changelog entry.
| File | Description |
|---|---|
cloudsmith_cli/cli/utils.py |
Adds shared JSON config validation. |
cloudsmith_cli/cli/tests/commands/test_config_file_json.py |
Tests four invalid inputs across 10 commands. |
cloudsmith_cli/cli/commands/upstream.py |
Validates configs for upstream creation and updates. |
cloudsmith_cli/cli/commands/repos.py |
Validates configs for repository creation and updates. |
cloudsmith_cli/cli/commands/policy/vulnerability.py |
Uses shared validation for vulnerability policies. |
cloudsmith_cli/cli/commands/policy/license.py |
Uses shared validation for license policies. |
cloudsmith_cli/cli/commands/policy/deny.py |
Uses shared validation for deny policies. |
CHANGELOG.md |
Documents the improved config-file error handling. |
Review effort: Balanced
`repos`, `upstream` and `policy` create/update loaded their config file with a bare `json.load`, so a malformed file (e.g. a trailing comma) crashed with an unhandled `JSONDecodeError`, and a non-object document crashed on `.get`. Add `utils.load_json_config_file`, which raises `click.BadParameter` for both cases, and use it in all 10 call sites. Sentry: CLOUDSMITH-CLI-2V Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MwJPoDcCsm7Cp96AeCALZ3
cloudsmith-iduffy
force-pushed
the
fix/handle-invalid-json-config-files
branch
from
November 21, 2026 23:51
2ed7206 to
9603649
Compare
cloudsmith-iduffy
enabled auto-merge (squash)
November 21, 2026 23:51
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.
Description
Fixes CLOUDSMITH-CLI-2V:
cloudsmith repos createcrashed with an unhandledJSONDecodeErrorwhen the config file had a trailing comma.The same bare
json.load(config_file)was used in 10 commands:repos create/updateupstream <format> create/updatepolicy deny|license|vulnerability create/updateA valid JSON document that isn't an object (e.g.
[...]) also crashed later on.get.This PR adds
utils.load_json_config_file(file, param_hint), which follows the existingread_privileges_filepattern and raisesclick.BadParameterfor invalid JSON, non-UTF-8 input, or a non-object document. All 10 call sites now use it.Before:
After (exit code 2, no API call, nothing sent to Sentry):
Type of Change
Additional Notes
cli/tests/commands/test_config_file_json.pycovers 10 commands × 4 bad inputs (trailing comma, empty, non-UTF-8, non-object), 40 cases. All 40 fail onmasterand pass on this branch.Generated by Claude Code