fix(pkg/engine): Catch non-templating errors when rendering templates

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5572/head
Ian Howell 6 years ago
parent 33b1ede570
commit 92b86f6e74

@ -154,7 +154,7 @@ func (e Engine) renderWithReferences(tpls, referenceTpls map[string]renderable)
for _, filename := range keys {
r := tpls[filename]
if _, err := t.New(filename).Parse(r.tpl); err != nil {
return map[string]string{}, parseTemplateError(err)
return map[string]string{}, parseTemplateError(filename, err)
}
}
@ -163,7 +163,7 @@ func (e Engine) renderWithReferences(tpls, referenceTpls map[string]renderable)
for filename, r := range referenceTpls {
if t.Lookup(filename) == nil {
if _, err := t.New(filename).Parse(r.tpl); err != nil {
return map[string]string{}, parseTemplateError(err)
return map[string]string{}, parseTemplateError(filename, err)
}
}
}
@ -180,7 +180,7 @@ func (e Engine) renderWithReferences(tpls, referenceTpls map[string]renderable)
vals["Template"] = chartutil.Values{"Name": filename, "BasePath": tpls[filename].basePath}
var buf strings.Builder
if err := t.ExecuteTemplate(&buf, filename, vals); err != nil {
return map[string]string{}, parseTemplateError(err)
return map[string]string{}, parseTemplateError(filename, err)
}
// Work around the issue where Go will emit "<no value>" even if Options(missing=zero)
@ -196,8 +196,12 @@ func (e Engine) renderWithReferences(tpls, referenceTpls map[string]renderable)
return rendered, nil
}
func parseTemplateError(err error) error {
func parseTemplateError(filename string, err error) error {
tokens := strings.Split(err.Error(), ": ")
if len(tokens) == 1 {
// This might happen if a non-templating error occurs
return fmt.Errorf("render error in %s: %q", filename, err)
}
// The first token is "template"
// The second token is either "filename:lineno" or "filename:lineNo:columnNo"
location := tokens[1]

Loading…
Cancel
Save