Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple recovery function added #388

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"net/http"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -125,7 +127,7 @@ func (p *Plugin) getCommandResponse(args *model.CommandArgs, text string) *model
}

// ExecuteCommand is the entrypoint for /gitlab commands. It returns a message to display to the user or an error.
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (res *model.CommandResponse, err *model.AppError) {
tschuyebuhl marked this conversation as resolved.
Show resolved Hide resolved
var (
split = strings.Fields(args.Command)
cmd = split[0]
Expand All @@ -145,6 +147,20 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
ctx, cancel := context.WithTimeout(context.Background(), commandTimeout)
defer cancel()

defer func() {
if r := recover(); r != nil {
p.client.Log.Warn("Recovered from a panic",
"Command", args.Command,
"UserId", args.UserId,
"error", r,
"stack", string(debug.Stack()))
err = model.NewAppError("ExecuteCommand", "plugin_gitlab.command.execute_command.panic", nil, "", http.StatusInternalServerError)
hanzei marked this conversation as resolved.
Show resolved Hide resolved
res = &model.CommandResponse{}
res.Text = "An unexpected error occurred. Please try again later."
hanzei marked this conversation as resolved.
Show resolved Hide resolved
res.Username = p.BotUserID
hanzei marked this conversation as resolved.
Show resolved Hide resolved
}
}()

if action == "about" {
text, err := command.BuildInfo(manifest)
if err != nil {
Expand Down