Display error log when a modified template has an error so that it could recovery when the error fixed (#22261) (#22321)

backport #22261 

A drawback is the previous generated template has been cached, so you
cannot get error in the UI but only from log

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: delvh <dev.lh@web.de>
pull/22320/head^2
Lunny Xiao 2 years ago committed by GitHub
parent 58e642c1d6
commit 791f290c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/templates/htmlrenderer.go

@ -77,7 +77,14 @@ func HTMLRenderer(ctx context.Context) (context.Context, *render.Render) {
if !setting.IsProd {
watcher.CreateWatcher(ctx, "HTML Templates", &watcher.CreateWatcherOpts{
PathsCallback: walkTemplateFiles,
BetweenCallback: renderer.CompileTemplates,
BetweenCallback: func() {
defer func() {
if err := recover(); err != nil {
log.Error("PANIC: %v\n%s", err, log.Stack(2))
}
}()
renderer.CompileTemplates()
},
})
}
return context.WithValue(ctx, rendererKey, renderer), renderer

Loading…
Cancel
Save