diff options
author | zeripath <art27@cantab.net> | 2022-10-07 22:02:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 22:02:24 +0100 |
commit | 7d2545d183058f98e96efb1bd972c2b841eebf43 (patch) | |
tree | 0bbc7c76de1e25b7205bb1e6cbbc7d3f5e46b600 /modules/templates/dynamic.go | |
parent | 56aabf3e8dbbf44c73766ad915cc4808d594b48e (diff) | |
download | gitea-7d2545d183058f98e96efb1bd972c2b841eebf43.tar.gz gitea-7d2545d183058f98e96efb1bd972c2b841eebf43.zip |
Add nicer error handling on template compile errors (#21350)
There are repeated issues reported whereby users are unable to interpret
the template errors. This PR adds some (somewhat complex) error handling
to the panic recovery for template renderering but hopefully makes the
interpretation of the error easier.
Reference #21344
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/templates/dynamic.go')
-rw-r--r-- | modules/templates/dynamic.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/templates/dynamic.go b/modules/templates/dynamic.go index 4896580f62..a86e71a8c8 100644 --- a/modules/templates/dynamic.go +++ b/modules/templates/dynamic.go @@ -33,6 +33,21 @@ func GetAsset(name string) ([]byte, error) { return os.ReadFile(filepath.Join(setting.StaticRootPath, name)) } +// GetAssetFilename returns the filename of the provided asset +func GetAssetFilename(name string) (string, error) { + filename := filepath.Join(setting.CustomPath, name) + _, err := os.Stat(filename) + if err != nil && !os.IsNotExist(err) { + return filename, err + } else if err == nil { + return filename, nil + } + + filename = filepath.Join(setting.StaticRootPath, name) + _, err = os.Stat(filename) + return filename, err +} + // walkTemplateFiles calls a callback for each template asset func walkTemplateFiles(callback func(path, name string, d fs.DirEntry, err error) error) error { if err := walkAssetDir(filepath.Join(setting.CustomPath, "templates"), true, callback); err != nil && !os.IsNotExist(err) { |