From 791f290c26c84bd9914c7bf6a1f48e6d2052bb09 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Jan 2023 19:39:58 +0800 Subject: [PATCH] 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 Co-authored-by: delvh --- modules/templates/htmlrenderer.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/templates/htmlrenderer.go b/modules/templates/htmlrenderer.go index 81ea66016..c3d747d12 100644 --- a/modules/templates/htmlrenderer.go +++ b/modules/templates/htmlrenderer.go @@ -76,8 +76,15 @@ func HTMLRenderer(ctx context.Context) (context.Context, *render.Render) { compilingTemplates = false if !setting.IsProd { watcher.CreateWatcher(ctx, "HTML Templates", &watcher.CreateWatcherOpts{ - PathsCallback: walkTemplateFiles, - BetweenCallback: renderer.CompileTemplates, + PathsCallback: walkTemplateFiles, + 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