From b2c9d2748a8ad0388342ad1919a791057f2f6944 Mon Sep 17 00:00:00 2001 From: Fork Less Date: Wed, 17 Jun 2026 02:10:47 +0200 Subject: [PATCH] fix: add panic recovery to ExecuteCommand to prevent plugin crash --- server/command.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/command.go b/server/command.go index 5cb0dd3..46f9df2 100644 --- a/server/command.go +++ b/server/command.go @@ -30,7 +30,17 @@ Also works with /ai . /ai new clears memory. ` // ExecuteCommand handles slash commands (/ai, /resetmatterless). -func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) { +func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (resp *model.CommandResponse, err *model.AppError) { + defer func() { + if r := recover(); r != nil { + p.API.LogError("ExecuteCommand panic", "recover", fmt.Sprintf("%v", r)) + resp = &model.CommandResponse{ + ResponseType: model.CommandResponseTypeEphemeral, + Text: "Command failed due to an internal error. Check server logs for details.", + } + } + }() + // /ai — dispatch subcommands. trigger := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(args.Command), "/ai")) parts := parseArgs(trigger)