Repository navigation
fix: strictly parse inline settings JSON instead of silently dropping it - #1352
tanveer-arch wants to merge 2 commits into
Conversation
|
Commenting rather than submitting a formal review: I am an outside contributor and not a triager for this area, so I have no review action to submit. But since you asked, here is what I verified rather than skimmed. At What I ran
I also did the A/B that matters for this issue: reverting only Two notes, neither blockingOn On the missing-file degradation. One thing I would raise with the maintainers, not with youThe strict inline parse is a behaviour change: anyone whose Thanks for picking this up and for stating the tested commit in the description. That made the verification straightforward. |
|
Thanks for the thorough verification the A/B check is a great sanity check, glad the tests pin the fix properly. On the ValueError vs hierarchy point: agreed, it's a deliberate tradeoff. The connect() path wraps it into CLIConnectionError with _exit_error set, and for direct _build_command() callers it's no worse than the bare JSONDecodeError it replaces — arguably more accurate for malformed input. On the changelog: happy to add an entry if the maintainers want one just let me know the preferred format/section. |
sigley
left a comment
There was a problem hiding this comment.
On exact head 755bd5a, the trailing-comma case is fixed, but the same silent-drop class remains for malformed inline JSON that does not end with a closing brace.
For example, with sandbox enabled:
settings = '{model:sonnet'
_build_settings_value() does not try JSON parsing because the discriminator requires both startswith({) and endswith(}). It falls into the file-path branch, logs:
Settings file not found: {model:sonnet
and returns only the sandbox settings. I reproduced that directly on this head; the five added focused tests also pass, so this boundary is currently unpinned.
That still conflicts with the new docstring/PR claim that an inline JSON string which fails to parse raises. Could the JSON-like discriminator avoid requiring the closing brace (for example, treat a stripped value starting with { as inline and parse it strictly), with a regression for a missing closing brace? Then malformed inline settings cannot be silently reinterpreted as a missing path.
… longer silently dropped)
|
Good catch fixed. The discriminator now treats any stripped value starting with { as inline JSON and parses it strictly, so '{model:sonnet' raises ValueError: Invalid JSON in inline settings string instead of falling through to the file-path branch. Added test_malformed_inline_settings_missing_brace_raises pinning that boundary (asserts the "Settings file not found" warning is gone too). All settings tests pass, ruff clean. |
sigley
left a comment
There was a problem hiding this comment.
Re-checked exact head 0d783b2 after the missing-brace fix. The discriminator now treats any stripped value beginning with { as inline JSON and parses it strictly, so malformed inline settings no longer fall through to the missing-file degradation path. The focused settings slice passes 10/10 and full tests/test_transport.py passes 210/210 locally, including after a clean merge with current main. This resolves my prior blocker.
Fixes #1335.
Tested against commit 755bd5a.
When
sandboxis set, a malformed inline settings string (e.g. one trailing comma) was silently discarded — the run proceeded with only the sandbox settings while looking healthy — accompanied by a misleading "treating as file path" warning naming the JSON text itself. The file form raised a bareJSONDecodeErrorthat escaped theClaudeSDKErrorhierarchy (_build_command()was called one line above thetryinconnect(), so_exit_errorwas never set).This PR, following the direction blessed in the issue:
ValueErroridentifying it as the inline settings string;_build_command()inside thetryinconnect()so both error shapes stay inside theClaudeSDKErrorhierarchy with_exit_errorset.Adds 5 regression tests covering the full behavior matrix, asserting on both the raised errors and the warning contents. Full suite: 1489 passed.
Credit to @feiiiiii5 for the detailed analysis and behavior matrix in the issue.