diff --git a/internal/wasm/sdk/internal/wasm/bindings.go b/internal/wasm/sdk/internal/wasm/bindings.go index 6e0b3d6f0f..79a55ab94d 100644 --- a/internal/wasm/sdk/internal/wasm/bindings.go +++ b/internal/wasm/sdk/internal/wasm/bindings.go @@ -153,8 +153,10 @@ func (d *builtinDispatcher) Call(caller *wasmtime.Caller, args []wasmtime.Val) ( if e, ok := e.Err.(*topdown.Error); ok && e.Code == topdown.CancelErr { panic(cancelledError{message: e.Message}) } + panic(builtinError{err: err}) } - panic(builtinError{err: err}) + // non-halt errors are treated as undefined ("non-strict eval" is the only + // mode in wasm), the `output == nil` case below will return NULL } // if output is undefined, return NULL diff --git a/rego/rego_wasmtarget_test.go b/rego/rego_wasmtarget_test.go index 8853d5cb78..dd70ae44c6 100644 --- a/rego/rego_wasmtarget_test.go +++ b/rego/rego_wasmtarget_test.go @@ -197,7 +197,7 @@ allow { target: "wasm", policy: httpSend, errorCheck: func(err error) bool { - return err == nil + return errors.Is(err, sdk_errors.ErrCancelled) }, }, { diff --git a/test/cases/testdata/functionerrors/test-functionerrors-undefined-builtin-result.yaml b/test/cases/testdata/functionerrors/test-functionerrors-undefined-builtin-result.yaml new file mode 100644 index 0000000000..d75b1b313e --- /dev/null +++ b/test/cases/testdata/functionerrors/test-functionerrors-undefined-builtin-result.yaml @@ -0,0 +1,12 @@ +cases: +- data: + modules: + - | + package test + foo = units.parse_bytes("1KB") + bar = units.parse_bytes("foo") # undefined + note: functionerrors/undefined builtin result + query: data.test = x + want_result: + - x: + foo: 1000 \ No newline at end of file