From 4b9a9ecaf64acddea4f8a2cc5d22a8ad04d8b727 Mon Sep 17 00:00:00 2001 From: Jesse Simpson Date: Sun, 16 Mar 2025 21:21:04 -0400 Subject: [PATCH] refactor: rename function and add doc-string Signed-off-by: Jesse Simpson --- pkg/engine/engine.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 3be69f1ab..cc1951af7 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -312,7 +312,7 @@ func (e Engine) render(tpls map[string]renderable) (rendered map[string]string, 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{}, cleanupExecError(filename, err) + return map[string]string{}, reformatExecErrorMsg(filename, err) } // Work around the issue where Go will emit "" even if Options(missing=zero) @@ -347,7 +347,14 @@ type TraceableError struct { func (t TraceableError) String() string { return t.location + "\n " + t.executedFunction + "\n " + t.message + "\n" } -func cleanupExecError(filename string, err error) error { + +// reformatExecErrorMsg takes an error message for template rendering and formats it into a formatted +// multi-line error string +func reformatExecErrorMsg(filename string, err error) error { + // This function matches the error message against regex's for the text/template package. + // If the regex's can parse out details from that error message such as the line number, template it failed on, + // and error description, then it will construct a new error that displays these details in a structured way. + // If there are issues with parsing the error message, the err passed into the function should return instead. if _, isExecError := err.(template.ExecError); !isExecError { return err }