All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.
Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.
Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
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>
Users of OPA as a library are concerned about big binary blobs in their vendor/
directories. Even more so if they don't use them. This is the case for anyone
using OPA as library, but not using the wasm-backed evaluation feature.
With this change, importers of any packages other than `server` and `cmd`
will have to explicitly opt-in to using wasm evaluation features by having an
underscore import somewhere:
import _ "github.com/open-policy-agent/opa/features/wasm"
Fixes#3545.
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Before, functions provided via arguments to `rego.New()` hadn't been
able to halt the topdown evaluation.
Now, they do, if they return a `*rego.HaltError`.
Fixes#3534.
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>