Skip to content

Commit

Permalink
feat(plc4xanalyzer): handle panics in actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Nov 1, 2022
1 parent f8b1de0 commit d136f7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plc4go/tools/plc4xpcapanalyzer/cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ TODO: document me
}()
}

defer ui.Shutdown()
if err := application.Run(); err != nil {
panic(err)
}
ui.Shutdown()
},
}

Expand Down
9 changes: 8 additions & 1 deletion plc4go/tools/plc4xpcapanalyzer/ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"os"
"path"
"reflect"
"runtime/debug"
"strings"
"time"
)
Expand Down Expand Up @@ -665,7 +666,13 @@ func Execute(ctx context.Context, commandText string) error {
return err
}

func (c Command) Execute(ctx context.Context, commandText string) error {
func (c Command) Execute(ctx context.Context, commandText string) (err error) {
defer func() {
if recoveredErr := recover(); recoveredErr != nil {
log.Debug().Msgf("Panic '%v' stack:\n%s", recoveredErr, debug.Stack())
err = errors.Errorf("panic occurred: %v.", recoveredErr)
}
}()
plc4xpcapanalyzerLog.Debug().Msgf("%s executes %s", c, commandText)
if !c.acceptsCurrentText(commandText) {
return errors.Errorf("%s doesn't understand %s", c.Name, commandText)
Expand Down

0 comments on commit d136f7a

Please sign in to comment.