Skip to content

Fix --string non-string error reporting#1039

Open
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/cli-string-non-string-error
Open

Fix --string non-string error reporting#1039
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/cli-string-non-string-error

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Motivation

--string mode leaked Internal error: upickle.core.Abort when the Jsonnet program produced a non-string result (object, array, number, boolean, null). Other implementations report a clean type error. The error path also lost the source position, making debugging harder.

Implementation --string on {}
C++ jsonnet 0.22.0 ERROR: expected string result, got: object
go-jsonnet 0.22.0 expected string result, got: object
sjsonnet master Internal error: upickle.core.Abort
this PR expected string result, got: object

Modification

  • Replace the generic SimpleVisitor that threw upickle.core.Abort with a typed visitor that overrides every non-string visitor method to throw sjsonnet.Error with a clear message including the Jsonnet type name (object, array, number, boolean, null).
  • Remove unnecessary return keyword in ManifestModule.scala match expression for idiomatic Scala.
  • Add a golden test for each non-string type and tighten existing --exec --string tests.

Result

  • Non-string results produce a clean sjsonnet.Error with position and Jsonnet type name.
  • String happy path is unchanged — zero overhead on the common case.
  • Error-path only: fillInStackTrace override prevents wasted JVM stack capture.

Motivation:
--string mode should reject non-string manifests with a normal Jsonnet-style error. Upstream sjsonnet only special-cased null with upickle.core.Abort, so other non-string values leaked as Internal error output with upickle details.

Modification:
Make the --string renderer throw sjsonnet.Error for every non-string visitor path, preserving string output unchanged and mapping non-string values to object/array/number/boolean/null. Add a CLI jsonnet+golden regression and tighten existing exec --string assertions.

Result:
Non-string --string outputs now fail with a clean sjsonnet.Error and no Internal error or upickle.core.Abort leakage across file and --exec inputs.
@He-Pin He-Pin force-pushed the fix/cli-string-non-string-error branch from 2dd17d0 to cedccb2 Compare June 25, 2026 04:48
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