fix: std.removeAt errors on invalid index instead of silently returning original array#946
Merged
stephenamar-db merged 2 commits intoJun 18, 2026
Conversation
Collaborator
|
rebase |
1bb3882 to
24efc79
Compare
…ng original array Motivation: std.removeAt silently returned the original array when given an out-of-bounds or negative index, masking bugs. go-jsonnet errors on invalid indices, which is the correct behavior. Modification: - Validate that idx is a number, an integer, and within bounds - Error with clear messages: "idx must be a number", "idx must be an integer", or "idx out of bounds" - Remove the silent fallback to return the original array Result: std.removeAt now errors on invalid indices, matching go-jsonnet behavior and helping users catch bugs earlier.
24efc79 to
d1481d9
Compare
Motivation: The error formatting infrastructure already prepends [std.removeAt] when errors originate from the removeAt builtin. The explicit "std.removeAt:" prefix in error messages produced doubled prefixes: "[std.removeAt] std.removeAt: idx out of bounds". Modification: Remove the "std.removeAt:" prefix from all three error messages in the removeAt builtin. Update golden files accordingly. Result: Error messages now read "[std.removeAt] idx out of bounds" instead of "[std.removeAt] std.removeAt: idx out of bounds", matching the style used by other stdlib functions.
stephenamar-db
approved these changes
Jun 18, 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.
Motivation
std.removeAtsilently returned the original array when given an invalid index (negative, out-of-bounds, or non-integer), instead of producing a clear error. go-jsonnet crashes with an internal error for negative indices; jrsonnet errors on non-integer indices but silently ignores negative ones.Modification
Result
std.removeAt([1,2,3], -1)now produces a clear "idx out of bounds" error instead of silently returning the original array.References
std.removeAt([1,2,3], 1)[1,3][1,3][1,3]✅[1,3]✅std.removeAt([1,2,3], -1)[1,2,3](wrong)[1,2,3](wrong) ❌std.removeAt([1,2,3], 1.5)[1,2,3](wrong) ❌std.removeAt([1,2,3], 10)[1,2,3](wrong)[1,2,3](wrong) ❌