-
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
CLI: display error details for ErrorDetail errors in eval output #3739
Merged
srenatus
merged 2 commits into
open-policy-agent:main
from
srenatus:sr/error-details-in-cli
Aug 18, 2021
Merged
CLI: display error details for ErrorDetail errors in eval output #3739
srenatus
merged 2 commits into
open-policy-agent:main
from
srenatus:sr/error-details-in-cli
Aug 18, 2021
Conversation
This file contains 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
Before, errors displayed through the presentation package's prettyError() method would never show their details. The expectation in the code was that any error that has details would include them in its own Error() string method. When error types return their details using an interface, such as type ErrorDetail interface { Lines() []string } and their Error() method only return a short error message, then that detail would never make it to the user in any of the non-JSON output variants. Before: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------\n" } ] } $ opa -fpretty -t wasm '1+1' 1 error occurred: engine not found Now: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------" } ] } $ opa eval -fpretty -t wasm '1+1' 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- This also surfaces the error details in REPL sessions: $ opa run OPA 0.32.0-dev (commit 3da95f9c-dirty, built at 2021-08-16T11:24:46Z) Run 'help' to see a list of commands and check for updates. > target wasm > true 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- > Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
srenatus
force-pushed
the
sr/error-details-in-cli
branch
from
August 16, 2021 11:54
f3ff8be
to
53568ef
Compare
tsandall
approved these changes
Aug 18, 2021
jgchn
pushed a commit
to jgchn/opa
that referenced
this pull request
Aug 20, 2021
…n-policy-agent#3739) Before, errors displayed through the presentation package's prettyError() method would never show their details. The expectation in the code was that any error that has details would include them in its own Error() string method. When error types return their details using an interface, such as type ErrorDetail interface { Lines() []string } and their Error() method only return a short error message, then that detail would never make it to the user in any of the non-JSON output variants. Before: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------\n" } ] } $ opa -fpretty -t wasm '1+1' 1 error occurred: engine not found Now: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------" } ] } $ opa eval -fpretty -t wasm '1+1' 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- This also surfaces the error details in REPL sessions: $ opa run OPA 0.32.0-dev (commit 3da95f9c-dirty, built at 2021-08-16T11:24:46Z) Run 'help' to see a list of commands and check for updates. > target wasm > true 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- > Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
dolevf
pushed a commit
to dolevf/opa
that referenced
this pull request
Nov 4, 2021
…n-policy-agent#3739) Before, errors displayed through the presentation package's prettyError() method would never show their details. The expectation in the code was that any error that has details would include them in its own Error() string method. When error types return their details using an interface, such as type ErrorDetail interface { Lines() []string } and their Error() method only return a short error message, then that detail would never make it to the user in any of the non-JSON output variants. Before: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------\n" } ] } $ opa -fpretty -t wasm '1+1' 1 error occurred: engine not found Now: $ opa eval -t wasm '1+1' { "errors": [ { "message": "engine not found", "details": "WebAssembly runtime not supported in this build.\n----------------------------------------------------------------------------------\nPlease download an OPA binary with Wasm enabled from\nhttps://www.openpolicyagent.org/docs/latest/#running-opa\nor build it yourself (with Wasm enabled).\n----------------------------------------------------------------------------------" } ] } $ opa eval -fpretty -t wasm '1+1' 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- This also surfaces the error details in REPL sessions: $ opa run OPA 0.32.0-dev (commit 3da95f9c-dirty, built at 2021-08-16T11:24:46Z) Run 'help' to see a list of commands and check for updates. > target wasm > true 1 error occurred: engine not found WebAssembly runtime not supported in this build. ---------------------------------------------------------------------------------- Please download an OPA binary with Wasm enabled from https://www.openpolicyagent.org/docs/latest/#running-opa or build it yourself (with Wasm enabled). ---------------------------------------------------------------------------------- > Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com> Signed-off-by: Dolev Farhi <farhi.dolev@gmail.com>
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.
Before, errors displayed through the presentation package's prettyError()
method would never show their details. The expectation in the code was
that any error that has details would include them in its own Error()
string method.
When error types return their details using an interface, such as
and their Error() method only return a short error message, then that
detail would never make it to the user in any of the non-JSON output
variants.
Before:
Now:
This also surfaces the error details in REPL sessions: