Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print empty goja stacktraces on captured panics #3749

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically skipped on cleaning this up as it is currently in js/common package and I didn't want to introduce a potential breaking change.

Depending on the decision from #3748 we might delete it.

If we decided against it - I will probably want to move this off common and in hte js package as I don't think this is functionality anyone but k6 should have.

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