mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
plugins: Don't exit on duplicate plugin (#28390)
* plugins: Don't exit on duplicate plugin Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Add missing files Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix test Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -35,11 +35,25 @@ const (
|
||||
)
|
||||
|
||||
type PluginNotFoundError struct {
|
||||
PluginId string
|
||||
PluginID string
|
||||
}
|
||||
|
||||
func (e PluginNotFoundError) Error() string {
|
||||
return fmt.Sprintf("Plugin with id %s not found", e.PluginId)
|
||||
return fmt.Sprintf("plugin with ID %q not found", e.PluginID)
|
||||
}
|
||||
|
||||
type duplicatePluginError struct {
|
||||
Plugin *PluginBase
|
||||
ExistingPlugin *PluginBase
|
||||
}
|
||||
|
||||
func (e duplicatePluginError) Error() string {
|
||||
return fmt.Sprintf("plugin with ID %q already loaded from %q", e.Plugin.Id, e.ExistingPlugin.PluginDir)
|
||||
}
|
||||
|
||||
func (e duplicatePluginError) Is(err error) bool {
|
||||
_, ok := err.(duplicatePluginError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// PluginLoader can load a plugin.
|
||||
@@ -77,8 +91,8 @@ type PluginBase struct {
|
||||
}
|
||||
|
||||
func (pb *PluginBase) registerPlugin(base *PluginBase) error {
|
||||
if _, exists := Plugins[pb.Id]; exists {
|
||||
return fmt.Errorf("Plugin with ID %q already exists", pb.Id)
|
||||
if p, exists := Plugins[pb.Id]; exists {
|
||||
return duplicatePluginError{Plugin: pb, ExistingPlugin: p}
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(base.PluginDir, setting.StaticRootPath) {
|
||||
|
||||
Reference in New Issue
Block a user