From 5e85257d3c7c82c08853221ad52dd12c78407a20 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 28 Dec 2022 21:21:59 +0800 Subject: [PATCH 1/2] display error log when a modified template has an error so that it could recovery when the error fixed --- modules/templates/htmlrenderer.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/templates/htmlrenderer.go b/modules/templates/htmlrenderer.go index 7ab523822b42d..b7dda716fb91d 100644 --- a/modules/templates/htmlrenderer.go +++ b/modules/templates/htmlrenderer.go @@ -75,8 +75,16 @@ 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 { + combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) + log.Error("%s", combinedErr) + } + }() + renderer.CompileTemplates() + }, }) } return context.WithValue(ctx, rendererKey, renderer), renderer From 824f2095e85061e03802ca2f17e50601d6e2ec3f Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 28 Dec 2022 15:18:39 +0100 Subject: [PATCH 2/2] Update modules/templates/htmlrenderer.go Co-authored-by: delvh --- modules/templates/htmlrenderer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/templates/htmlrenderer.go b/modules/templates/htmlrenderer.go index b7dda716fb91d..5a328043ebfe4 100644 --- a/modules/templates/htmlrenderer.go +++ b/modules/templates/htmlrenderer.go @@ -79,8 +79,7 @@ func HTMLRenderer(ctx context.Context) (context.Context, *render.Render) { BetweenCallback: func() { defer func() { if err := recover(); err != nil { - combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) - log.Error("%s", combinedErr) + log.Error("PANIC: %v\n%s", err, log.Stack(2)) } }() renderer.CompileTemplates()