From 6cd0c0082a4f0c996adc7d71328b5d0d8953f1b8 Mon Sep 17 00:00:00 2001 From: Jesse Simpson Date: Mon, 23 Dec 2024 14:44:37 -0500 Subject: [PATCH] fix: split up the multiline errors to be more vertical Signed-off-by: Jesse Simpson --- pkg/engine/engine.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 65e633f89..0336801c6 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -331,8 +331,9 @@ func cleanupParseError(filename string, err error) error { } type TraceableError struct { - location string - message string + location string + message string + executedFunction string } func cleanupExecError(filename string, err error) error { @@ -390,12 +391,35 @@ func cleanupExecError(filename string, err error) error { } } + for i := len(fileLocations) - 1; i >= 0; i-- { + if strings.Contains(fileLocations[i].message, "template:") { + fileLocations[i].message = strings.TrimSpace(strings.ReplaceAll(fileLocations[i].message, "template:", "")) + } + if strings.HasPrefix(fileLocations[i].message, ": ") { + fileLocations[i].message = strings.TrimSpace(strings.TrimPrefix(fileLocations[i].message, ": ")) + } + } + + for i := len(fileLocations) - 1; i >= 0; i-- { + if fileLocations[i].message == "" { + continue + } + executionLocationRegex, regexFindErr := regexp.Compile(`executing "[^\"]*" at <[^\<\>]*>:?\s*`) + if regexFindErr != nil { + continue + } + byteArrayMsg := []byte(fileLocations[i].message) + executionLocations := executionLocationRegex.FindAll(byteArrayMsg, -1) + fileLocations[i].executedFunction = string(executionLocations[0]) + fileLocations[i].message = strings.ReplaceAll(fileLocations[i].message, fileLocations[i].executedFunction, "") + } + finalErrorString := "" for _, i := range fileLocations { if i.message == "" { continue } - finalErrorString = finalErrorString + "\n" + i.location + " " + i.message + finalErrorString = finalErrorString + "\n" + i.location + "\n " + i.executedFunction + "\n " + i.message } return fmt.Errorf("NEW ERROR FORMAT: \n%s\n\n\nORIGINAL ERROR:\n%s", finalErrorString, err.Error())