Better error handling for failed plugin activation (#8361)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ff5f511dfd
Коммит
4ae1238bc1
@@ -91,18 +91,11 @@ func (a *App) ActivatePlugins() {
|
||||
active := a.PluginEnv.IsPluginActive(id)
|
||||
|
||||
if pluginState.Enable && !active {
|
||||
if err := a.PluginEnv.ActivatePlugin(id); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
if err := a.activatePlugin(plugin.Manifest); err != nil {
|
||||
l4g.Error("%v plugin enabled in config.json but failing to activate err=%v", plugin.Manifest.Id, err.DetailedError)
|
||||
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 {
|
||||
if err := a.deactivatePlugin(plugin.Manifest); err != nil {
|
||||
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 {
|
||||
if err := a.PluginEnv.DeactivatePlugin(manifest.Id); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
if err := a.activatePlugin(manifest); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
|
||||
})
|
||||
|
||||
Ссылка в новой задаче
Block a user