You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/11/01 13:10:04 UTC

[plc4x] branch develop updated: feat(plc4xanalyzer): handle panics in actions

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new d136f7a22 feat(plc4xanalyzer): handle panics in actions
d136f7a22 is described below

commit d136f7a223e9f14e87bdd0278b47ba6c517c8b8d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Nov 1 14:09:57 2022 +0100

    feat(plc4xanalyzer): handle panics in actions
---
 plc4go/tools/plc4xpcapanalyzer/cmd/ui.go      | 2 +-
 plc4go/tools/plc4xpcapanalyzer/ui/commands.go | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/plc4go/tools/plc4xpcapanalyzer/cmd/ui.go b/plc4go/tools/plc4xpcapanalyzer/cmd/ui.go
index 0a259a15d..3d3f83ae0 100644
--- a/plc4go/tools/plc4xpcapanalyzer/cmd/ui.go
+++ b/plc4go/tools/plc4xpcapanalyzer/cmd/ui.go
@@ -59,10 +59,10 @@ TODO: document me
 			}()
 		}
 
+		defer ui.Shutdown()
 		if err := application.Run(); err != nil {
 			panic(err)
 		}
-		ui.Shutdown()
 	},
 }
 
diff --git a/plc4go/tools/plc4xpcapanalyzer/ui/commands.go b/plc4go/tools/plc4xpcapanalyzer/ui/commands.go
index 272d923c8..d2e2f2df0 100644
--- a/plc4go/tools/plc4xpcapanalyzer/ui/commands.go
+++ b/plc4go/tools/plc4xpcapanalyzer/ui/commands.go
@@ -34,6 +34,7 @@ import (
 	"os"
 	"path"
 	"reflect"
+	"runtime/debug"
 	"strings"
 	"time"
 )
@@ -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)