Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: display error details for ErrorDetail errors in eval output
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>
- Loading branch information