fix(pkg/engine): Style changes on template errors

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

@ -200,14 +200,14 @@ func parseTemplateError(filename string, err error) error {
tokens := strings.Split(err.Error(), ": ") tokens := strings.Split(err.Error(), ": ")
if len(tokens) == 1 { if len(tokens) == 1 {
// This might happen if a non-templating error occurs // This might happen if a non-templating error occurs
return fmt.Errorf("render error in %s: %q", filename, err) return fmt.Errorf("render error in (%s): %s", filename, err)
} }
// The first token is "template" // The first token is "template"
// The second token is either "filename:lineno" or "filename:lineNo:columnNo" // The second token is either "filename:lineno" or "filename:lineNo:columnNo"
location := tokens[1] location := tokens[1]
// The remaining tokens make up a stacktrace-like chain, ending with the relevant error // The remaining tokens make up a stacktrace-like chain, ending with the relevant error
errMsg := tokens[len(tokens)-1] errMsg := tokens[len(tokens)-1]
return fmt.Errorf("%s (%s)", errMsg, string(location)) return fmt.Errorf("render error at (%s): %s", string(location), errMsg)
} }
func sortTemplates(tpls map[string]renderable) []string { func sortTemplates(tpls map[string]renderable) []string {

@ -197,7 +197,7 @@ func TestRenderErrors(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("Expected failures while rendering: %s", err) t.Fatalf("Expected failures while rendering: %s", err)
} }
expected := `foo is required (missing_required:1:2)` expected := `render error at (missing_required:1:2): foo is required`
if err.Error() != expected { if err.Error() != expected {
t.Errorf("Expected '%s', got %q", expected, err.Error()) t.Errorf("Expected '%s', got %q", expected, err.Error())
} }
@ -209,7 +209,7 @@ func TestRenderErrors(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("Expected failures while rendering: %s", err) t.Fatalf("Expected failures while rendering: %s", err)
} }
expected = `function "foo" not defined (undefined_function:1)` expected = `render error at (undefined_function:1): function "foo" not defined`
if err.Error() != expected { if err.Error() != expected {
t.Errorf("Expected '%s', got %q", expected, err.Error()) t.Errorf("Expected '%s', got %q", expected, err.Error())
} }

Loading…
Cancel
Save