Skip to content

Commit ad340f7

Browse files
authored
tweak how wasm runnable errors are handled (#201)
1 parent d8f95a1 commit ad340f7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rwasm/wasmrunnable.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (w *Runner) Run(job rt.Job, ctx *rt.Ctx) (interface{}, error) {
6666

6767
var output []byte
6868
var runErr error
69+
var callErr error
6970

7071
if err := w.env.UseInstance(ctx, func(instance *runtime.WasmInstance, ident int32) {
7172
inPointer, writeErr := instance.WriteMemory(jobBytes)
@@ -75,8 +76,8 @@ func (w *Runner) Run(job rt.Job, ctx *rt.Ctx) (interface{}, error) {
7576
}
7677

7778
// execute the Runnable's Run function, passing the input data and ident
78-
// set runErr but don't return because the ExecutionResult error should override the Call error
79-
_, runErr = instance.Call("run_e", inPointer, int32(len(jobBytes)), ident)
79+
// set runErr but don't return because the ExecutionResult error should also be grabbed
80+
_, callErr = instance.Call("run_e", inPointer, int32(len(jobBytes)), ident)
8081

8182
// get the results from the instance
8283
output, runErr = instance.ExecutionResult()
@@ -93,6 +94,13 @@ func (w *Runner) Run(job rt.Job, ctx *rt.Ctx) (interface{}, error) {
9394
return nil, runErr
9495
}
9596

97+
if callErr != nil {
98+
// if the runnable didn't return an explicit runErr, still check to see if there was an
99+
// error executing the module in the first place. It's posslble for both to be non-nil
100+
// in which case returning the runErr takes precedence, which is why it's checked first.
101+
return nil, errors.Wrap(callErr, "wasm execution error")
102+
}
103+
96104
if req != nil {
97105
resp := &request.CoordinatedResponse{
98106
Output: output,

0 commit comments

Comments
 (0)