fix: add panic recovery to ExecuteCommand to prevent plugin crash
This commit is contained in:
+11
-1
@@ -30,7 +30,17 @@ Also works with /ai <prompt>. /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)
|
||||
|
||||
Reference in New Issue
Block a user