Better error handling for failed plugin activation (#8361)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ff5f511dfd
Коммит
4ae1238bc1
@@ -91,18 +91,11 @@ func (a *App) ActivatePlugins() {
|
|||||||
active := a.PluginEnv.IsPluginActive(id)
|
active := a.PluginEnv.IsPluginActive(id)
|
||||||
|
|
||||||
if pluginState.Enable && !active {
|
if pluginState.Enable && !active {
|
||||||
if err := a.PluginEnv.ActivatePlugin(id); err != nil {
|
if err := a.activatePlugin(plugin.Manifest); err != nil {
|
||||||
l4g.Error(err.Error())
|
l4g.Error("%v plugin enabled in config.json but failing to activate err=%v", plugin.Manifest.Id, err.DetailedError)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if plugin.Manifest.HasClient() {
|
|
||||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_ACTIVATED, "", "", "", nil)
|
|
||||||
message.Add("manifest", plugin.Manifest.ClientManifest())
|
|
||||||
a.Publish(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
l4g.Info("Activated %v plugin", id)
|
|
||||||
} else if !pluginState.Enable && active {
|
} else if !pluginState.Enable && active {
|
||||||
if err := a.deactivatePlugin(plugin.Manifest); err != nil {
|
if err := a.deactivatePlugin(plugin.Manifest); err != nil {
|
||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
@@ -111,6 +104,21 @@ func (a *App) ActivatePlugins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) activatePlugin(manifest *model.Manifest) *model.AppError {
|
||||||
|
if err := a.PluginEnv.ActivatePlugin(manifest.Id); err != nil {
|
||||||
|
return model.NewAppError("activatePlugin", "app.plugin.activate.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if manifest.HasClient() {
|
||||||
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_ACTIVATED, "", "", "", nil)
|
||||||
|
message.Add("manifest", manifest.ClientManifest())
|
||||||
|
a.Publish(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
l4g.Info("Activated %v plugin", manifest.Id)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) deactivatePlugin(manifest *model.Manifest) *model.AppError {
|
func (a *App) deactivatePlugin(manifest *model.Manifest) *model.AppError {
|
||||||
if err := a.PluginEnv.DeactivatePlugin(manifest.Id); err != nil {
|
if err := a.PluginEnv.DeactivatePlugin(manifest.Id); err != nil {
|
||||||
return model.NewAppError("removePlugin", "app.plugin.deactivate.app_error", nil, err.Error(), http.StatusBadRequest)
|
return model.NewAppError("removePlugin", "app.plugin.deactivate.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
@@ -301,6 +309,10 @@ func (a *App) EnablePlugin(id string) *model.AppError {
|
|||||||
return model.NewAppError("EnablePlugin", "app.plugin.not_installed.app_error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("EnablePlugin", "app.plugin.not_installed.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := a.activatePlugin(manifest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
a.UpdateConfig(func(cfg *model.Config) {
|
a.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
|
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -195,3 +197,26 @@ func TestPluginCommands(t *testing.T) {
|
|||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pluginBadActivation struct {
|
||||||
|
testPlugin
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pluginBadActivation) OnActivate(api plugin.API) error {
|
||||||
|
return errors.New("won't activate for some reason")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginBadActivation(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.InstallPlugin(&model.Manifest{
|
||||||
|
Id: "foo",
|
||||||
|
}, &pluginBadActivation{})
|
||||||
|
|
||||||
|
t.Run("EnablePlugin bad activation", func(t *testing.T) {
|
||||||
|
err := th.App.EnablePlugin("foo")
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
assert.True(t, strings.Contains(err.DetailedError, "won't activate for some reason"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user