Skip to content

fix: error expression produces clean message for function values#970

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

fix: error expression produces clean message for function values#970
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/error-function-message

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Summary

Fix error expression to produce a clean message for function values instead of leaking internal parameter details.

Motivation

error function(x) x produced a misleading message like "Couldn't manifest function with params [x]" instead of a clear error about attempting to serialize a function. Both go-jsonnet and jrsonnet produce cleaner error messages.

Modification

Add a Val.Func case to Evaluator.materializeError so that error expressions with function values produce "Couldn't manifest function as JSON" — aligned with go-jsonnet's "couldn't manifest function as JSON" and jrsonnet's "tried to manifest function".

Result

error function(x) x now produces a clean, implementation-consistent error message instead of leaking internal parameter details.

Behavior Comparison

Impl Error message for error function(x) x
go-jsonnet v0.22.0 RUNTIME ERROR: couldn't manifest function as JSON
jsonnet-cpp v0.22.0 RUNTIME ERROR: couldn't manifest function as JSON
jrsonnet v0.5.0-pre99 runtime error: tried to manifest function
sjsonnet (before) sjsonnet.Error: Couldn't manifest function with params [x]
sjsonnet (after) sjsonnet.Error: Couldn't manifest function as JSON

Test plan

  • error function(x) x produces clean error message
  • Existing error_function_fail.jsonnet golden updated
  • New directional test error.error_function.jsonnet added
  • All FileTests and EvaluatorTests pass
  • Code passes scalafmt
  • Verified against go-jsonnet v0.22.0, jsonnet-cpp v0.22.0, and jrsonnet v0.5.0-pre99

Motivation:
`error function(x) x` produced a misleading message like "Couldn't
manifest function with params [x]" instead of a clear error about
attempting to serialize a function.

Modification:
Add a Val.Func case to Evaluator.materializeError so that error
expressions with function values produce "Couldn't manifest function
as JSON" — aligned with go-jsonnet's "couldn't manifest function as
JSON" and jrsonnet's "tried to manifest function".

Result:
`error function(x) x` now produces a clean, implementation-consistent
error message instead of leaking internal parameter details.

| Impl | Error message |
|------|--------------|
| go-jsonnet v0.22.0 | RUNTIME ERROR: couldn't manifest function as JSON |
| jrsonnet 0.5.0-pre99 | runtime error: tried to manifest function |
| sjsonnet (before) | Couldn't manifest function with params [x] |
| sjsonnet (after) | Couldn't manifest function as JSON |
@He-Pin He-Pin force-pushed the fix/error-function-message branch from b606786 to dc4424b Compare June 18, 2026 10:11
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