Skip to content

fix: std.parseJson reports truncated input cleanly#1042

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

fix: std.parseJson reports truncated input cleanly#1042
He-Pin wants to merge 1 commit 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 should report incomplete JSON input as a Jsonnet runtime error instead of leaking an internal ujson exception. Before this change, empty or truncated JSON strings produced [std.parseJson] Internal Error, which made the user-facing failure look like an interpreter bug.

Modification

  • Catch ujson.IncompleteParseException in std.parseJson.
  • Report Invalid JSON: unexpected end of JSON input through the existing Error.fail path.
  • Add regression goldens for empty input and truncated object input.

Result

Case go-jsonnet v0.22.0 jrsonnet 0.5.0-pre99 sjsonnet before sjsonnet after
std.parseJson("") failed to parse JSON: unexpected end of JSON input failed to parse json: EOF while parsing a value [std.parseJson] Internal Error [std.parseJson] Invalid JSON: unexpected end of JSON input
std.parseJson('{"a":') failed to parse JSON: unexpected end of JSON input failed to parse json: EOF while parsing a value at line 1 column 5 [std.parseJson] Internal Error [std.parseJson] Invalid JSON: unexpected end of JSON input

The PR only changes ManifestModule.scala and the two regression tests with their goldens.

Risks

  • This intentionally changes the exact error text for incomplete JSON input.
  • Other malformed JSON errors continue to use the existing parse-error path.

@He-Pin He-Pin marked this pull request as ready for review June 25, 2026 06:20
@He-Pin He-Pin force-pushed the fix/parsejson-incomplete-error branch 2 times, most recently from e58c801 to b7932d1 Compare June 28, 2026 17:15
@stephenamar-db

Copy link
Copy Markdown
Collaborator

This PR seems incorrect. a lot of files are modified.

@He-Pin He-Pin force-pushed the fix/parsejson-incomplete-error branch from b7932d1 to d244bc7 Compare June 28, 2026 21:40
@He-Pin He-Pin marked this pull request as draft June 28, 2026 21:54
Motivation:
std.parseJson on empty or truncated JSON input leaked the underlying parser's incomplete-input failure instead of returning a stable sjsonnet error.

Modification:
Handle ujson.IncompleteParseException in std.parseJson and add new_test_suite regressions for empty and truncated JSON input.

Result:
Incomplete JSON input now reports a concise Invalid JSON error.
@He-Pin He-Pin force-pushed the fix/parsejson-incomplete-error branch from d244bc7 to 9fc7301 Compare June 28, 2026 22:04
@He-Pin He-Pin marked this pull request as ready for review June 28, 2026 22:25
@He-Pin

He-Pin commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

fixed

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.

2 participants