Commit 2528241
authored
fix: std.parseJson reports truncated input cleanly (#1042)
## 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.1 parent 628e0c1 commit 2528241
5 files changed
Lines changed: 6 additions & 0 deletions
File tree
- sjsonnet
- src/sjsonnet/stdlib
- test/resources/new_test_suite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments