Skip to content
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
merged 2 commits into from
Aug 18, 2021

Conversation

srenatus
Copy link
Contributor

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).
----------------------------------------------------------------------------------
>

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 srenatus force-pushed the sr/error-details-in-cli branch from f3ff8be to 53568ef Compare August 16, 2021 11:54
@srenatus srenatus merged commit f2db31d into open-policy-agent:main Aug 18, 2021
@srenatus srenatus deleted the sr/error-details-in-cli branch August 18, 2021 17:33
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants