[MM-18150] plugin panic trace should not be lost (#13559)

* Transit panic from debug to error

* Parse plugin's StdErr and output panic to the mlog.Error

* Add unit tests

* Change log test

* Remove buffer from logger

* Remove 'panic' string filter

* Change *Buffer to io.Writer

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Shota Gvinepadze
2020-03-11 11:41:11 +04:00
коммит произвёл GitHub
родитель 771574b652
Коммит 5d928b4f94
6 изменённых файлов: 76 добавлений и 6 удалений

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

@@ -13,6 +13,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"
@@ -626,6 +627,49 @@ func TestPluginSync(t *testing.T) {
}
}
func TestPluginPanicLogs(t *testing.T) {
t.Run("should panic", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := 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) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
panic("some text from panic")
return nil, ""
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`,
}, th.App, th.App.NewPluginAPI)
defer tearDown()
post := &model.Post{
UserId: th.BasicUser.Id,
ChannelId: th.BasicChannel.Id,
Message: "message_",
CreateAt: model.GetMillis() - 10000,
}
_, err := th.App.CreatePost(post, th.BasicChannel, false)
assert.Nil(t, err)
logs := th.LogBuffer.String()
assert.True(t, strings.Contains(logs, "some text from panic"))
})
}
func TestProcessPrepackagedPlugins(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()