mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
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>
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user