From d3d1f66c3d2352f0b31d6acbc8e0e17b113d73e2 Mon Sep 17 00:00:00 2001 From: Clemens Lang Date: Fri, 12 Sep 2025 23:01:59 +0200 Subject: [PATCH] Log stack trace when recovering from a panic Apparently that's possible by attempting to capture a stack trace at this location, even though it isn't the location where the error was thrown, at least according to [1]. It seems to work in my testing. [1]: https://groups.google.com/g/golang-nuts/c/MB8GyW5j2UY/m/xt54dFicvxoJ --- pr/webhook/pull_request.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pr/webhook/pull_request.go b/pr/webhook/pull_request.go index d1bde6a..82bdf56 100644 --- a/pr/webhook/pull_request.go +++ b/pr/webhook/pull_request.go @@ -4,6 +4,7 @@ import ( "encoding/json" "log" "regexp" + "runtime/debug" "strconv" "strings" @@ -15,7 +16,7 @@ var cveRegexp = regexp.MustCompile(`CVE-\d{4}-\d+`) func (receiver *Receiver) handlePullRequest(body []byte) { defer func() { if r := recover(); r != nil { - log.Println(r) + log.Printf("PR processing failed: %s\n%s", r, debug.Stack()) } if !receiver.testing {