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
This commit is contained in:
Clemens Lang
2025-09-12 23:01:59 +02:00
parent e0682b4b28
commit d3d1f66c3d
+2 -1
View File
@@ -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 {