Skip to content

Commit

Permalink
fix: return Extism error message regardless of the return code (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored Nov 21, 2024
1 parent 6a22323 commit bef00f3
Showing 1 changed file with 12 additions and 9 deletions.
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

0 comments on commit bef00f3

Please sign in to comment.