Show the JSON parse-error message on the Variable form warning - #71780
Draft
pierrejeambrun wants to merge 1 commit into
Draft
Show the JSON parse-error message on the Variable form warning#71780pierrejeambrun wants to merge 1 commit into
pierrejeambrun wants to merge 1 commit into
Conversation
The Variables form warns "Invalid JSON" the moment the value looks
like it might be JSON but doesn't parse. That warning tells the user
something's wrong but not where, so a typo halfway through a large
value is still a hunt.
The browser's SyntaxError from JSON.parse already carries the position
("Unexpected token ',' at position 42 (line 3 column 12)" on V8,
similar on Firefox / Safari). Surface it alongside the localized label
so users can jump straight to the character that broke the parse.
The parser message is emitted by the JS engine and is only ever in
English — mixing it with a localized label is a compromise, but the
position info is more valuable than perfect localization here, and no
browser offers a localized JSON parse error to begin with.
closes: apache#68262
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.
The Variables form warns "Invalid JSON" the moment the value looks like it might be JSON but doesn't parse. That warning tells the user something's wrong but not where, so a typo halfway through a large value is still a hunt.
The browser's
SyntaxErrorfromJSON.parsealready carries the position ("Unexpected token ',' at position 42 (line 3 column 12)"on V8; similar on Firefox / Safari). Surface it alongside the localized label so users can jump straight to the character that broke the parse.Caveat worth naming up front. The parser message is emitted by the JS engine and is only ever in English — mixing it with a localized label is a compromise. The position info is more valuable than perfect localization here IMO, and no browser offers a localized JSON parse error to begin with. Alternative would be a dependency like
jsonc-parserfor a cross-browser structured error, which is ~30KB for a UI hint.Existing test cases (Jinja template
{{ var.value.x }}, bracket-prefixed plain string[DRAFT] ..., malformed object with trailing comma) still hit the same warning path — just with a browser-provided detail message now. Updated thegetByTextassertions to a regex so they don't depend on the exact detail suffix, which varies by browser.closes: #68262
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines