Skip to content

fix: std.parseJson reports truncated input cleanly#1042

Open
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/parsejson-incomplete-error
Open

fix: std.parseJson reports truncated input cleanly#1042
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/parsejson-incomplete-error

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Motivation

std.parseJson on truncated/incomplete JSON input leaked a raw Java ujson.IncompleteParseException stack trace instead of a clean error message. The catch block only handled ujson.ParseException but not its sibling IncompleteParseException.

Input sjsonnet master go-jsonnet this PR
'{"a":' Internal Error + full Java stack trace failed to parse JSON: unexpected end of JSON input Invalid JSON: unexpected end of JSON input
"" Internal Error + full Java stack trace failed to parse JSON: unexpected end of JSON input Invalid JSON: unexpected end of JSON input
"[1,2" Internal Error + full Java stack trace failed to parse JSON: unexpected end of JSON input Invalid JSON: unexpected end of JSON input

Modification

  • Catch ujson.IncompleteParseException alongside ParseException in ManifestModule.ParseJson.evalRhs.
  • Produce a clean "Invalid JSON: unexpected end of JSON input" message matching go-jsonnet's wording.
  • Add golden test for truncated JSON input.

Result

  • Truncated JSON input produces a clean CLI error with no stack trace leakage.
  • Happy path and malformed (non-truncated) JSON are unaffected.
  • All tests pass on JVM 2.12, 2.13, 3.3.

References

  • ujson exception hierarchy: ParseException and IncompleteParseException both implement ParsingFailedException but neither extends the other.

Motivation:
std.parseJson on truncated/incomplete JSON input leaked a raw Java
ujson.IncompleteParseException stack trace instead of a clean error
message. The catch block only handled ujson.ParseException but not its
sibling IncompleteParseException.

Modification:
- Catch ujson.IncompleteParseException alongside ParseException in
  ManifestModule.ParseJson.evalRhs.
- Produce a clean "Invalid JSON: unexpected end of JSON input" message
  matching go-jsonnet's wording for truncated input.
- Add golden test for truncated JSON input.

Result:
- Truncated JSON input produces a clean CLI error with no stack trace.
- Happy path and malformed (non-truncated) JSON are unaffected.
@He-Pin He-Pin marked this pull request as ready for review June 25, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant