From 227a664b06702856a2b499ebbe72c9ab3e86a236 Mon Sep 17 00:00:00 2001 From: Calvin Leung Huang Date: Thu, 15 Nov 2018 16:55:24 -0800 Subject: [PATCH] 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 --- command/server.go | 19 ++++++++++++++++--- vault/plugin_catalog.go | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/command/server.go b/command/server.go index b1cc61d8e..705aa3a32 100644 --- a/command/server.go +++ b/command/server.go @@ -967,7 +967,7 @@ CLUSTER_SYNTHESIS_COMPLETE: return 1 } - var plugins []string + var plugins, pluginsNotLoaded []string if c.flagDevPluginDir != "" && c.flagDevPluginInit { f, err := os.Open(c.flagDevPluginDir) @@ -986,8 +986,12 @@ CLUSTER_SYNTHESIS_COMPLETE: for _, name := range list { path := filepath.Join(f.Name(), name) if err := c.addPlugin(path, init.RootToken, core); err != nil { - c.UI.Error(fmt.Sprintf("Error enabling plugin %s: %s", name, err)) - return 1 + if !errwrap.Contains(err, vault.ErrPluginBadType.Error()) { + c.UI.Error(fmt.Sprintf("Error enabling plugin %s: %s", name, err)) + return 1 + } + pluginsNotLoaded = append(pluginsNotLoaded, name) + continue } 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(wrapAtLength( "Development mode should NOT be used in production installations!")) diff --git a/vault/plugin_catalog.go b/vault/plugin_catalog.go index ad5fc2b4d..b81b024aa 100644 --- a/vault/plugin_catalog.go +++ b/vault/plugin_catalog.go @@ -26,6 +26,7 @@ var ( pluginCatalogPath = "core/plugin-catalog/" ErrDirectoryNotConfigured = errors.New("could not set plugin, plugin directory is not configured") 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 @@ -270,7 +271,7 @@ func (c *PluginCatalog) setInternal(ctx context.Context, name string, pluginType pluginType, err = c.getPluginTypeFromUnknown(ctx, entryTmp) if err != nil || pluginType == consts.PluginTypeUnknown { - return errors.New("unable to determine plugin type") + return ErrPluginBadType } }