fix: add panic recovery to ExecuteCommand to prevent plugin crash

This commit is contained in:
2026-06-17 02:10:47 +02:00
parent b3cec4f4cc
commit b2c9d2748a
+11 -1
View File
@@ -30,7 +30,17 @@ Also works with /ai <prompt>. /ai new clears memory.
` `
// ExecuteCommand handles slash commands (/ai, /resetmatterless). // 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. // /ai — dispatch subcommands.
trigger := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(args.Command), "/ai")) trigger := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(args.Command), "/ai"))
parts := parseArgs(trigger) parts := parseArgs(trigger)