aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-03 12:57:22 +0800
committerGitHub <noreply@github.com>2024-03-03 04:57:22 +0000
commite71b69257c38178eed9ccd0b62a5ae47d67858d4 (patch)
tree29f230d82e7abd7167e4eb0c69830c58dbd99f57 /modules/templates
parent22b4f0c09f1de5e581929bd10f39833d30d2c482 (diff)
downloadgitea-e71b69257c38178eed9ccd0b62a5ae47d67858d4.tar.gz
gitea-e71b69257c38178eed9ccd0b62a5ae47d67858d4.zip
Breaking summary for template refactoring (#29395)
https://github.com/go-gitea/gitea/pull/29395
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/mailer.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/modules/templates/mailer.go b/modules/templates/mailer.go
index 04032e3982..f1832cba0e 100644
--- a/modules/templates/mailer.go
+++ b/modules/templates/mailer.go
@@ -5,6 +5,7 @@ package templates
import (
"context"
+ "fmt"
"html/template"
"regexp"
"strings"
@@ -33,7 +34,7 @@ func mailSubjectTextFuncMap() texttmpl.FuncMap {
}
}
-func buildSubjectBodyTemplate(stpl *texttmpl.Template, btpl *template.Template, name string, content []byte) {
+func buildSubjectBodyTemplate(stpl *texttmpl.Template, btpl *template.Template, name string, content []byte) error {
// Split template into subject and body
var subjectContent []byte
bodyContent := content
@@ -42,20 +43,13 @@ func buildSubjectBodyTemplate(stpl *texttmpl.Template, btpl *template.Template,
subjectContent = content[0:loc[0]]
bodyContent = content[loc[1]:]
}
- if _, err := stpl.New(name).
- Parse(string(subjectContent)); err != nil {
- log.Error("Failed to parse template [%s/subject]: %v", name, err)
- if !setting.IsProd {
- log.Fatal("Please fix the mail template error")
- }
+ if _, err := stpl.New(name).Parse(string(subjectContent)); err != nil {
+ return fmt.Errorf("failed to parse template [%s/subject]: %w", name, err)
}
- if _, err := btpl.New(name).
- Parse(string(bodyContent)); err != nil {
- log.Error("Failed to parse template [%s/body]: %v", name, err)
- if !setting.IsProd {
- log.Fatal("Please fix the mail template error")
- }
+ if _, err := btpl.New(name).Parse(string(bodyContent)); err != nil {
+ return fmt.Errorf("failed to parse template [%s/body]: %w", name, err)
}
+ return nil
}
// Mailer provides the templates required for sending notification mails.
@@ -87,7 +81,13 @@ func Mailer(ctx context.Context) (*texttmpl.Template, *template.Template) {
if firstRun {
log.Trace("Adding mail template %s: %s by %s", tmplName, assetPath, layerName)
}
- buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, tmplName, content)
+ if err = buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, tmplName, content); err != nil {
+ if firstRun {
+ log.Fatal("Failed to parse mail template, err: %v", err)
+ } else {
+ log.Error("Failed to parse mail template, err: %v", err)
+ }
+ }
}
}