fix: unify assertion message handling in objects#907
Merged
stephenamar-db merged 1 commit intoJun 9, 2026
Conversation
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
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.cast[Val.Str].strfor the message, producing a confusing "Expected string, found number" error when the assertion message is not a string (e.g.,assert false : 42)materializeErrorwhich produces the helpful "Assertion failed: 42"Verification against go-jsonnet
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
error.object_assert_non_string_msg.jsonnet