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 <deluan@navidrome.org>
This commit is contained in:
Deluan Quintão 2025-07-07 16:24:10 -03:00 committed by GitHub
parent f1f1fd2007
commit d041cb3249
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 9 deletions

View File

@ -78,10 +78,6 @@ type wasmPlugin[S any] interface {
getMetrics() metrics.Metrics 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) { 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 // Add a unique call ID to the context for tracing
ctx = log.NewContext(ctx, "callID", id.NewRandom()) 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)) r, err = checkErr(fn(inst))
elapsed := time.Since(start) elapsed := time.Since(start)
if em, ok := any(p).(errorMapper); ok {
err = em.mapError(err)
}
if !errors.Is(err, api.ErrNotImplemented) { if !errors.Is(err, api.ErrNotImplemented) {
id := p.PluginID() id := p.PluginID()
isOk := err == nil isOk := err == nil

View File

@ -82,7 +82,7 @@ func (m *pluginLifecycleManager) callOnInit(plugin *plugin) error {
// Call OnInit // Call OnInit
callStart := time.Now() callStart := time.Now()
_, err = checkErr(initPlugin.OnInit(ctx, req)) _, 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 { if err != nil {
log.Error("Error initializing plugin", "plugin", plugin.ID, "elapsed", time.Since(start), err) log.Error("Error initializing plugin", "plugin", plugin.ID, "elapsed", time.Since(start), err)
return err return err