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

Graceful error handling for host function calls from guest modules #89

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleaned up based on PR feedback
clarkmcc committed Dec 4, 2024
commit 3a64cc06320b666b977ea7fc8176bfd624e37289
1 change: 0 additions & 1 deletion extism.go
Original file line number Diff line number Diff line change
@@ -110,7 +110,6 @@ type Plugin struct {
close []func(ctx context.Context) error
extism api.Module

hostFuncError error
module api.Module
Timeout time.Duration
Config map[string]string
6 changes: 3 additions & 3 deletions host.go
Original file line number Diff line number Diff line change
@@ -109,9 +109,9 @@ func (p *Plugin) currentPlugin() *CurrentPlugin {
return &CurrentPlugin{p}
}

// SetHostFunctionError allows the host function to set an error that will be
// SetError allows the host function to set an error that will be
// gracefully returned by extism guest modules.
func (p *CurrentPlugin) SetHostFunctionError(ctx context.Context, err error) {
func (p *CurrentPlugin) SetError(ctx context.Context, err error) {
if err == nil {
return
}
@@ -255,7 +255,7 @@ func defineCustomHostFunctions(builder wazero.HostModuleBuilder, funcs []HostFun
// See: https://github.com/extism/go-sdk/issues/5#issuecomment-1666774486
closure := f.stackCallback

builder.NewFunctionBuilder().WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) {
builder.NewFunctionBuilder().WithGoFunction(api.GoFunc(func(ctx context.Context, stack []uint64) {
if plugin, ok := ctx.Value(PluginCtxKey("plugin")).(*Plugin); ok {
closure(ctx, &CurrentPlugin{plugin}, stack)
return