From 868f2920046413312bf16df9c05d5e69691b7d75 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Thu, 4 Jul 2024 00:27:33 +0000 Subject: [PATCH] runtime: Print stack trace with panics --- runtime/applet.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/applet.go b/runtime/applet.go index ff0406820f..f7d9247656 100644 --- a/runtime/applet.go +++ b/runtime/applet.go @@ -6,6 +6,7 @@ import ( "fmt" "io/fs" "path" + "runtime/debug" "slices" "strings" "testing" @@ -291,7 +292,7 @@ func (app *Applet) RunTests(t *testing.T) { func (a *Applet) Call(ctx context.Context, callable *starlark.Function, args ...starlark.Value) (val starlark.Value, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("panic while running %s: %v", a.ID, r) + err = fmt.Errorf("panic while running %s: %v\n%s", a.ID, r, debug.Stack()) } }() @@ -357,7 +358,7 @@ func (a *Applet) load(fsys fs.FS) (err error) { func (a *Applet) ensureLoaded(fsys fs.FS, pathToLoad string, currentlyLoading ...string) (err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("panic while executing %s: %v", a.ID, r) + err = fmt.Errorf("panic while executing %s: %v\n%s", a.ID, r, debug.Stack()) } }()