Continue on plugin registration error in dev mode (#5791)

* Continue on plugin registration error in dev mode

* Continue only on unknown type error

* Continue only on unknown type error

* Print plugin registration error on exit

Co-Authored-By: calvn <cleung2010@gmail.com>
This commit is contained in:
Calvin Leung Huang 2018-11-15 16:55:24 -08:00 committed by Brian Kassouf
parent e99957aed9
commit 227a664b06
2 changed files with 18 additions and 4 deletions

View File

@ -967,7 +967,7 @@ CLUSTER_SYNTHESIS_COMPLETE:
return 1 return 1
} }
var plugins []string var plugins, pluginsNotLoaded []string
if c.flagDevPluginDir != "" && c.flagDevPluginInit { if c.flagDevPluginDir != "" && c.flagDevPluginInit {
f, err := os.Open(c.flagDevPluginDir) f, err := os.Open(c.flagDevPluginDir)
@ -986,9 +986,13 @@ CLUSTER_SYNTHESIS_COMPLETE:
for _, name := range list { for _, name := range list {
path := filepath.Join(f.Name(), name) path := filepath.Join(f.Name(), name)
if err := c.addPlugin(path, init.RootToken, core); err != nil { if err := c.addPlugin(path, init.RootToken, core); err != nil {
if !errwrap.Contains(err, vault.ErrPluginBadType.Error()) {
c.UI.Error(fmt.Sprintf("Error enabling plugin %s: %s", name, err)) c.UI.Error(fmt.Sprintf("Error enabling plugin %s: %s", name, err))
return 1 return 1
} }
pluginsNotLoaded = append(pluginsNotLoaded, name)
continue
}
plugins = append(plugins, name) plugins = append(plugins, name)
} }
@ -1044,6 +1048,15 @@ CLUSTER_SYNTHESIS_COMPLETE:
} }
} }
if len(pluginsNotLoaded) > 0 {
c.UI.Warn("")
c.UI.Warn(wrapAtLength(
"The following dev plugins FAILED to be registered in the catalog due to unknown type:"))
for _, p := range pluginsNotLoaded {
c.UI.Warn(fmt.Sprintf(" - %s", p))
}
}
c.UI.Warn("") c.UI.Warn("")
c.UI.Warn(wrapAtLength( c.UI.Warn(wrapAtLength(
"Development mode should NOT be used in production installations!")) "Development mode should NOT be used in production installations!"))

View File

@ -26,6 +26,7 @@ var (
pluginCatalogPath = "core/plugin-catalog/" pluginCatalogPath = "core/plugin-catalog/"
ErrDirectoryNotConfigured = errors.New("could not set plugin, plugin directory is not configured") ErrDirectoryNotConfigured = errors.New("could not set plugin, plugin directory is not configured")
ErrPluginNotFound = errors.New("plugin not found in the catalog") ErrPluginNotFound = errors.New("plugin not found in the catalog")
ErrPluginBadType = errors.New("unable to determine plugin type")
) )
// PluginCatalog keeps a record of plugins known to vault. External plugins need // PluginCatalog keeps a record of plugins known to vault. External plugins need
@ -270,7 +271,7 @@ func (c *PluginCatalog) setInternal(ctx context.Context, name string, pluginType
pluginType, err = c.getPluginTypeFromUnknown(ctx, entryTmp) pluginType, err = c.getPluginTypeFromUnknown(ctx, entryTmp)
if err != nil || pluginType == consts.PluginTypeUnknown { if err != nil || pluginType == consts.PluginTypeUnknown {
return errors.New("unable to determine plugin type") return ErrPluginBadType
} }
} }