[MM-24753] Improves error message when plugin crashes during slash command (#15334)

Co-authored-by: Ali Farooq <ali.farooq0@pm.me>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Ashim Sedhain
2020-10-02 03:02:58 -05:00
коммит произвёл GitHub
родитель 51d790300f
Коммит 2f47cf5994
5 изменённых файлов: 113 добавлений и 3 удалений

Просмотреть файл

@@ -286,4 +286,94 @@ func TestPluginCommand(t *testing.T) {
th.App.RemovePlugin(pluginIds[0])
})
t.Run("plugin has crashed before execution of command", func(t *testing.T) {
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
package main
import (
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/model"
)
type MyPlugin struct {
plugin.MattermostPlugin
}
func (p *MyPlugin) OnActivate() error {
err := p.API.RegisterCommand(&model.Command{
Trigger: "code",
})
if err != nil {
p.API.LogError("error", "err", err)
}
panic("Uncaught Error")
return err
}
func (p *MyPlugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
return &model.CommandResponse{}, nil
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`}, th.App, th.App.NewPluginAPI)
defer tearDown()
require.Len(t, activationErrors, 1)
require.Nil(t, nil, activationErrors[0])
args.Command = "/code"
resp, err := th.App.ExecuteCommand(args)
require.Nil(t, resp)
require.NotNil(t, err)
require.Equal(t, err.Id, "model.plugin_command_error.error.app_error")
th.App.RemovePlugin(pluginIds[0])
})
t.Run("plugin has crashed due to the execution of the command", func(t *testing.T) {
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
package main
import (
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/model"
)
type MyPlugin struct {
plugin.MattermostPlugin
}
func (p *MyPlugin) OnActivate() error {
err := p.API.RegisterCommand(&model.Command{
Trigger: "code",
})
if err != nil {
p.API.LogError("error", "err", err)
}
return err
}
func (p *MyPlugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
panic("Uncaught Error")
return &model.CommandResponse{}, nil
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`}, th.App, th.App.NewPluginAPI)
defer tearDown()
require.Len(t, activationErrors, 1)
require.Nil(t, nil, activationErrors[0])
args.Command = "/code"
resp, err := th.App.ExecuteCommand(args)
require.Nil(t, resp)
require.NotNil(t, err)
require.Equal(t, err.Id, "model.plugin_command_crash.error.app_error")
th.App.RemovePlugin(pluginIds[0])
})
}