Print panic message when mmctl panics (#27390)

Этот коммит содержится в:
Ben Schumacher
2024-07-02 13:58:37 +02:00
коммит произвёл GitHub
родитель a3c1272cb6
Коммит 213ebc57fb
3 изменённых файлов: 38 добавлений и 7 удалений

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

@@ -4,6 +4,8 @@
package commands
import (
"fmt"
"net/url"
"os"
"path/filepath"
"runtime/debug"
@@ -56,10 +58,9 @@ func Run(args []string) error {
defer func() {
if x := recover(); x != nil {
printer.PrintError("Uh oh! Something unexpected happened :( Would you mind reporting it?\n")
printer.PrintError(`https://github.com/mattermost/mmctl/issues/new?title=%5Bbug%5D%20panic%20on%20mmctl%20v` + Version + "&body=%3C!---%20Please%20provide%20the%20stack%20trace%20--%3E\n")
printer.PrintError(string(debug.Stack()))
printPanic(x)
_ = printer.Flush()
os.Exit(1)
}
}()
@@ -67,6 +68,23 @@ func Run(args []string) error {
return RootCmd.Execute()
}
func printPanic(x any) {
u, err := url.Parse("https://github.com/mattermost/mattermost/issues/new")
if err != nil {
panic(err)
}
q := u.Query()
q.Add("title", "[mmctl] [bug] panic on v"+Version)
q.Add("body", "<!--- Please provide the stack trace -->\n")
u.RawQuery = q.Encode()
printer.PrintError("Uh oh! Something unexpected happened :( Would you mind reporting it?")
printer.PrintError(u.String() + "\n")
printer.PrintError(fmt.Sprintf("%s", x))
printer.PrintError(string(debug.Stack()))
}
var RootCmd = &cobra.Command{
Use: "mmctl",
Short: "Remote client for the Open Source, self-hosted Slack-alternative",