Plugins: Do not fail bootstrap stage if single decorate step fails (#73147)
* don't fail all if decorate step fails * fix casing * include err too * cover pluginsintegration too
This commit is contained in:
@@ -60,12 +60,12 @@ func (v *ModuleJSValidator) Validate(_ context.Context, p *plugins.Plugin) error
|
||||
f, err := p.FS.Open("module.js")
|
||||
if err != nil {
|
||||
if errors.Is(err, plugins.ErrFileNotExist) {
|
||||
v.log.Warn("Plugin missing module.js", "pluginID", p.ID,
|
||||
v.log.Warn("Plugin missing module.js", "pluginId", p.ID,
|
||||
"warning", "Missing module.js, If you loaded this plugin from git, make sure to compile it.")
|
||||
}
|
||||
} else if f != nil {
|
||||
if err = f.Close(); err != nil {
|
||||
v.log.Warn("Could not close module.js", "pluginID", p.ID, "err", err)
|
||||
v.log.Warn("Could not close module.js", "pluginId", p.ID, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,12 +99,12 @@ func (a *AngularDetector) Validate(ctx context.Context, p *plugins.Plugin) error
|
||||
canc()
|
||||
|
||||
if err != nil {
|
||||
a.log.Warn("Could not inspect plugin for angular", "pluginID", p.ID, "err", err)
|
||||
a.log.Warn("Could not inspect plugin for angular", "pluginId", p.ID, "error", err)
|
||||
}
|
||||
|
||||
// Do not initialize plugins if they're using Angular and Angular support is disabled
|
||||
if p.AngularDetected && !a.cfg.AngularSupportEnabled {
|
||||
a.log.Error("Refusing to initialize plugin because it's using Angular, which has been disabled", "pluginID", p.ID)
|
||||
a.log.Error("Refusing to initialize plugin because it's using Angular, which has been disabled", "pluginId", p.ID)
|
||||
return errors.New("angular plugins are not supported")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
@@ -41,27 +40,26 @@ func New(cfg *config.Cfg, opts Opts) *Validate {
|
||||
}
|
||||
|
||||
// Validate will execute the Validate steps of the Validation stage.
|
||||
func (t *Validate) Validate(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error) {
|
||||
if len(t.validateSteps) == 0 {
|
||||
func (v *Validate) Validate(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error) {
|
||||
if len(v.validateSteps) == 0 {
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
verifiedPlugins := make([]*plugins.Plugin, 0, len(ps))
|
||||
validatedPlugins := make([]*plugins.Plugin, 0, len(ps))
|
||||
for _, p := range ps {
|
||||
stepFailed := false
|
||||
for _, validate := range t.validateSteps {
|
||||
err = validate(ctx, p)
|
||||
if err != nil && !errors.Is(err, nil) {
|
||||
for _, validate := range v.validateSteps {
|
||||
err := validate(ctx, p)
|
||||
if err != nil {
|
||||
stepFailed = true
|
||||
t.log.Error("Plugin verification failed", "pluginID", p.ID, "err", err)
|
||||
v.log.Error("Plugin validation failed", "pluginId", p.ID, "error", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !stepFailed {
|
||||
verifiedPlugins = append(verifiedPlugins, p)
|
||||
validatedPlugins = append(validatedPlugins, p)
|
||||
}
|
||||
}
|
||||
|
||||
return verifiedPlugins, nil
|
||||
return validatedPlugins, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user