Skip to content

Commit

Permalink
Don't print empty goja stacktraces on captured panics
Browse files Browse the repository at this point in the history
This has been broken for years after some goja refactoring.

There doesn't seem to be a way for this to be fixed without a lot of
boilerplate all over the code. And this functionality has not been used
in the last few years in my experience.

closes #1906
  • Loading branch information
mstoykov committed May 20, 2024
1 parent 153e0e5 commit 3723047
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions js/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,15 @@ func ToString(data interface{}) (string, error) {
}

// RunWithPanicCatching catches panic and converts into an InterruptError error that should abort a script
func RunWithPanicCatching(logger logrus.FieldLogger, rt *goja.Runtime, fn func() error) (err error) {
func RunWithPanicCatching(logger logrus.FieldLogger, _ *goja.Runtime, fn func() error) (err error) {
defer func() {
if r := recover(); r != nil {
gojaStack := rt.CaptureCallStack(20, nil)

err = &errext.InterruptError{Reason: fmt.Sprintf("a panic occurred during JS execution: %s", r)}
// TODO figure out how to use PanicLevel without panicing .. this might require changing
// the logger we use see
// https://github.com/sirupsen/logrus/issues/1028
// https://github.com/sirupsen/logrus/issues/993
b := new(bytes.Buffer)
for _, s := range gojaStack {
s.Write(b)
}
logger.Error("panic: ", r, "\n", string(debug.Stack()), "\nGoja stack:\n", b.String())
logger.Error("panic: ", r, "\n", string(debug.Stack()))
}
}()

Expand Down

0 comments on commit 3723047

Please sign in to comment.