diff options
author | zeripath <art27@cantab.net> | 2021-08-23 20:40:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 20:40:59 +0100 |
commit | 73defbbd1c070930563f17daa9e540c44a127928 (patch) | |
tree | 30bd32b42eac15bd8bf074b57ae98a91b8912edc /cmd | |
parent | 94f529af02e74f5d13fefda48d3ef9db4559f71f (diff) | |
download | gitea-73defbbd1c070930563f17daa9e540c44a127928.tar.gz gitea-73defbbd1c070930563f17daa9e540c44a127928.zip |
Ensure that template compilation panics are sent to the logs (#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 <art27@cantab.net>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/web.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/cmd/web.go b/cmd/web.go index 6953e7c64f..963c816207 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -86,6 +86,11 @@ func runWeb(ctx *cli.Context) error { _ = log.DelLogger("console") log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout)) } + defer func() { + if panicked := recover(); panicked != nil { + log.Fatal("PANIC: %v\n%s", panicked, string(log.Stack(2))) + } + }() managerCtx, cancel := context.WithCancel(context.Background()) graceful.InitManager(managerCtx) |