blob: 22079112762373546f70fa8ab36ec546447b742b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package hotline
import (
"log/slog"
"runtime/debug"
)
// dontPanic recovers from a panic and logs it (with a stack trace) instead of
// letting it crash the goroutine. The trace is recorded via the structured
// logger only; it is intentionally not written to stdout, so a client that can
// repeatedly trigger a panic cannot flood stdout.
func dontPanic(logger *slog.Logger) {
if r := recover(); r != nil {
logger.Error("PANIC", "err", r, "trace", string(debug.Stack()))
}
}
|