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

fix: return Extism error message regardless of the return code #86

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions extism.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,20 +525,23 @@ func (p *Plugin) CallWithContext(ctx context.Context, name string, data []byte)
return rc, []byte{}, err
}

if rc != 0 {
errMsg := p.GetError()
if errMsg == "" {
errMsg = "encountered an unknown error in call to Extism p function " + name
}
return rc, []byte{}, errors.New(errMsg)
var returnErr error = nil
errMsg := p.GetErrorWithContext(ctx)
if errMsg != "" {
returnErr = errors.New(errMsg)
}

output, err := p.GetOutput()
output, err := p.GetOutputWithContext(ctx)
if err != nil {
return rc, []byte{}, fmt.Errorf("failed to get output: %v", err)
e := fmt.Errorf("failed to get output: %v", err)
if returnErr != nil {
return rc, []byte{}, errors.Join(returnErr, e)
} else {
return rc, []byte{}, e
}
}

return rc, output, nil
return rc, output, returnErr
}

func calculateHash(data []byte) string {
Expand Down
Loading