Skip to content

Improve runtime error when indexing a non-indexable value#883

Open
ricardbejarano wants to merge 1 commit into
google:masterfrom
bejaratommy:fix/index-non-indexable-error
Open

Improve runtime error when indexing a non-indexable value#883
ricardbejarano wants to merge 1 commit into
google:masterfrom
bejaratommy:fix/index-non-indexable-error

Conversation

@ricardbejarano

Copy link
Copy Markdown

Summary

Indexing a non-indexable value produced an error that leaked the internal Go type name:

RUNTIME ERROR: Value non indexable: *jsonnet.valueNull

This is confusing for users, who have no notion of *jsonnet.valueNull. The message now uses the jsonnet type name and explains which types can be indexed:

RUNTIME ERROR: Could not index a value of type "null" (only objects, arrays and strings can be indexed)

Changes

  • interpreter.go: build the error from targetValue.getType().name instead of reflect.TypeOf, matching how other runtime type errors are reported in this file.
  • jsonnet_test.go: add a test covering null, number, boolean and function targets, asserting the message mentions the jsonnet type and does not leak internal Go type names.

Fixes #258

The error for indexing a non-indexable value exposed the internal Go type
name, e.g. `RUNTIME ERROR: Value non indexable: *jsonnet.valueNull`. Use the
jsonnet type name instead and explain which types can be indexed, e.g.
`Could not index a value of type "null" (only objects, arrays and strings can
be indexed)`.

Fixes google#258
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.

[Easy] Better runtime error when indexing a non-indexable value

2 participants