Skip to content

Commit e58c801

Browse files
committed
fix: std.parseJson reports truncated input cleanly
Motivation: Truncated std.parseJson input could surface incomplete parser failures poorly. Modification: Map incomplete ujson parse failures to clean sjsonnet errors and add regressions. Result: Truncated JSON input now reports a clear user-facing parse error.
1 parent f189a95 commit e58c801

5 files changed

Lines changed: 6 additions & 0 deletions

File tree

sjsonnet/src/sjsonnet/stdlib/ManifestModule.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ object ManifestModule extends AbstractFunctionModule {
130130
} catch {
131131
case e: ujson.ParseException =>
132132
throw Error.fail("Invalid JSON: " + e.getMessage, pos)(ev)
133+
case _: ujson.IncompleteParseException =>
134+
throw Error.fail("Invalid JSON: unexpected end of JSON input", pos)(ev)
133135
}
134136
}
135137
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
std.parseJson("")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sjsonnet.Error: [std.parseJson] Invalid JSON: unexpected end of JSON input
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
std.parseJson('{"a":')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sjsonnet.Error: [std.parseJson] Invalid JSON: unexpected end of JSON input

0 commit comments

Comments
 (0)