From 7451953d432ca4bc002b1a422e65b81babad0c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 30 Jan 2024 10:55:49 -0800 Subject: [PATCH] reexport RegenerateTemplateCache() and have it return error instead of dying --- internal/render/render.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/render/render.go b/internal/render/render.go index a90529f..5513cc7 100644 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -37,7 +37,10 @@ func Initialise(a *config.AppConfig) { func RenderTemplate(w http.ResponseWriter, filename string) { // TODO: implement this better if !app.UseCache { - regenerateTemplateCache() + err := RegenerateTemplateCache() + if err != nil { + app.Logger.Fatal("Regenerating template cache failed!", err, "err") + } } template, err := GetTemplateFromCache(filename) @@ -59,7 +62,10 @@ func RenderTemplate(w http.ResponseWriter, filename string) { func RenderTemplateWithData(w http.ResponseWriter, filename string, data *models.TemplateData) { if !app.UseCache { - regenerateTemplateCache() + err := RegenerateTemplateCache() + if err != nil { + app.Logger.Fatal("Regenerating template cache failed!", err, "err") + } } template, err := GetTemplateFromCache(filename) @@ -104,13 +110,15 @@ func GetOrGenerateTemplateData(filename string) (*models.TemplateData, error) { return &data, nil } -// regenerateTemplateCache regenerates the template cache -func regenerateTemplateCache() { +// RegenerateTemplateCache regenerates the template cache +func RegenerateTemplateCache() error { c, err := generateNewTemplateCache() if err != nil { - app.Logger.Fatal("Error generating template cache, bailing out!", "err", err) + // app.Logger.Fatal("Error generating template cache, bailing out!", "err", err) + return err } app.TemplateCache = c + return nil }