From d041cb3249955bac969ca5d4efc9d50f3be0d23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Mon, 7 Jul 2025 16:24:10 -0300 Subject: [PATCH] fix(plugins): correct error handling in plugin initialization (#4311) Updated the error handling logic in the plugin lifecycle manager to accurately record the success of the OnInit method. The change ensures that the metrics reflect whether the initialization was successful, improving the reliability of plugin metrics tracking. Additionally, removed the unused errorMapper interface from base_capability.go to clean up the codebase. Signed-off-by: Deluan --- plugins/base_capability.go | 8 -------- plugins/plugin_lifecycle_manager.go | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/base_capability.go b/plugins/base_capability.go index 140fadd7..7a67b146 100644 --- a/plugins/base_capability.go +++ b/plugins/base_capability.go @@ -78,10 +78,6 @@ type wasmPlugin[S any] interface { getMetrics() metrics.Metrics } -type errorMapper interface { - mapError(err error) error -} - func callMethod[S any, R any](ctx context.Context, wp WasmPlugin, methodName string, fn func(inst S) (R, error)) (R, error) { // Add a unique call ID to the context for tracing ctx = log.NewContext(ctx, "callID", id.NewRandom()) @@ -102,10 +98,6 @@ func callMethod[S any, R any](ctx context.Context, wp WasmPlugin, methodName str r, err = checkErr(fn(inst)) elapsed := time.Since(start) - if em, ok := any(p).(errorMapper); ok { - err = em.mapError(err) - } - if !errors.Is(err, api.ErrNotImplemented) { id := p.PluginID() isOk := err == nil diff --git a/plugins/plugin_lifecycle_manager.go b/plugins/plugin_lifecycle_manager.go index 36d215af..e00e7e5f 100644 --- a/plugins/plugin_lifecycle_manager.go +++ b/plugins/plugin_lifecycle_manager.go @@ -82,7 +82,7 @@ func (m *pluginLifecycleManager) callOnInit(plugin *plugin) error { // Call OnInit callStart := time.Now() _, err = checkErr(initPlugin.OnInit(ctx, req)) - m.metrics.RecordPluginRequest(ctx, plugin.ID, "OnInit", err != nil, time.Since(callStart).Milliseconds()) + m.metrics.RecordPluginRequest(ctx, plugin.ID, "OnInit", err == nil, time.Since(callStart).Milliseconds()) if err != nil { log.Error("Error initializing plugin", "plugin", plugin.ID, "elapsed", time.Since(start), err) return err