Skip to content

fix: unify assertion message handling in objects#907

Merged
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/object-assert-message
Jun 9, 2026
Merged

fix: unify assertion message handling in objects#907
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/object-assert-message

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Summary

  • Object assertions used .cast[Val.Str].str for the message, producing a confusing "Expected string, found number" error when the assertion message is not a string (e.g., assert false : 42)
  • Top-level assertions already used materializeError which produces the helpful "Assertion failed: 42"
  • This fix makes object assertions consistent with top-level assertions

Verification against go-jsonnet

$ echo 'local obj = { assert false : 42, x: 1 }; obj.x' | jsonnet -
RUNTIME ERROR: 42

go-jsonnet uses "RUNTIME ERROR: " without "Assertion failed:" prefix. sjsonnet uses its own "Assertion failed: " convention for both top-level and object assertions. This fix ensures internal consistency within sjsonnet.

Test plan

  • Added golden error test error.object_assert_non_string_msg.jsonnet
  • Full test suite passes (all 519 tests)

Motivation:
Object assertions used `.cast[Val.Str].str` for the message, producing
a confusing "Expected string, found number" error when the assertion
message is not a string (e.g., `assert false : 42`). Top-level assertions
already use `materializeError` which produces the more helpful
"Assertion failed: 42".

Modification:
Replace `.cast[Val.Str].str` with `materializeError(...)` in the object
assertion evaluation path.

Result:
`{ assert false : 42 }.x` now produces "Assertion failed: 42" instead
of "Expected string, found number", consistent with top-level asserts.
@stephenamar-db stephenamar-db merged commit abe167a into databricks:master Jun 9, 2026
5 checks passed
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