From dbbbe325c35ebd25a93d856c6cbff4856d808d1d Mon Sep 17 00:00:00 2001 From: Red Daly Date: Tue, 4 Mar 2014 04:22:15 -0800 Subject: [PATCH] Improve error messages in template parsing init(). --- pkg/template/template.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/template/template.go b/pkg/template/template.go index 61ecbe11a..e360e3fe3 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -2,6 +2,7 @@ package template import ( "errors" + "fmt" "html/template" "io" @@ -109,7 +110,16 @@ func init() { } // parse the template and then add to the global map - registry[file] = template.Must(template.Must(template.New("_").Parse(baseTemplate)).Parse(page)) + baseParsed, err := template.New("_").Parse(baseTemplate) + if err != nil { + panic(fmt.Errorf("Error parsing base.html template: %s", err)) + } + pageParsed, err := baseParsed.Parse(page) + if err != nil { + panic(fmt.Errorf("Error parsing page template for %s: %s", file, err)) + } + + registry[file] = pageParsed } // location of templates @@ -136,8 +146,16 @@ func init() { if err != nil { panic(err) } + baseParsed, err := template.New("_").Parse(base) + if err != nil { + panic(fmt.Errorf("Error parsing base_email.html template: %s", err)) + } + emailParsed, err := baseParsed.Parse(email) + if err != nil { + panic(fmt.Errorf("Error parsing email template for %s: %s", file, err)) + } // parse the template and then add to the global map - registry[file] = template.Must(template.Must(template.New("_").Parse(base)).Parse(email)) + registry[file] = emailParsed } }