Skip to content

Commit 63178b5

Browse files
Ensure that template compilation panics are sent to the logs (#16788) (#16792)
Backport #16788 Although panics within the rendering pipeline are caught and dealt with, panics that occur before that starts are unprotected and will kill Gitea without being sent to the logs. This PR adds a basic recovery handler to catch panics that occur after the logger is initialised and ensure that they're sent to the logger. Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 2d15126 commit 63178b5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

cmd/web.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func runWeb(ctx *cli.Context) error {
8686
_ = log.DelLogger("console")
8787
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
8888
}
89+
defer func() {
90+
if panicked := recover(); panicked != nil {
91+
log.Fatal("PANIC: %v\n%s", panicked, string(log.Stack(2)))
92+
}
93+
}()
8994

9095
managerCtx, cancel := context.WithCancel(context.Background())
9196
graceful.InitManager(managerCtx)

0 commit comments

Comments
 (0)