-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error message when using an invalid object key #516
Comments
Looked at this one, we can improve the message. For example. for the policy below: `package foo
The message would be: "object value ({["foo"]: 456}) has non-string key of type ([]interface {}), value ([foo])" The "[]interface {}" comes from the fact that during parsing ["foo"] is considered an object of type []interface{} meaning basically we do not know what it is so consider it to map[]interface{} I will submit a pull |
We will not merging the changes due to: |
Previously, when OPA attempted to convert an ast.Object to interface{} it would error if the ast.Object contained any keys that were not ast.String values. This behaviour was implemented because JSON only supports object keys as strings. This commit changes the conversion implementation to simply JSON marshal non-string object keys when they are encountered. This way we avoid runtime errors which can be difficult to debug. Fixes open-policy-agent#516 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Previously, when OPA attempted to convert an ast.Object to interface{} it would error if the ast.Object contained any keys that were not ast.String values. This behaviour was implemented because JSON only supports object keys as strings. This commit changes the conversion implementation to simply JSON marshal non-string object keys when they are encountered. This way we avoid runtime errors which can be difficult to debug. Fixes #516 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
When using a non-string value as an object key, OPA returns an internal error, rather than a more specific error pointing out the error.
This can be reproduced using the following policy:
Response from OPA:
The text was updated successfully, but these errors were encountered: