diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index e06c18f34..0c7d72dba 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -347,6 +347,9 @@ func (t TraceableError) ExtractExecutedFunction() (TraceableError, error) { } byteArrayMsg := []byte(t.message) executionLocations := executionLocationRegex.FindAll(byteArrayMsg, -1) + if len(executionLocations) == 0 { + return t, nil + } t.executedFunction = string(executionLocations[0]) t.message = strings.ReplaceAll(t.message, t.executedFunction, "") return t, nil @@ -422,7 +425,12 @@ func cleanupExecError(filename string, err error) error { break } tokens = strings.SplitN(current.Error(), ": ", 3) - location = tokens[1] + if len(tokens) == 1 { + // For cases where the error message doesn't contain a colon + location = tokens[0] + } else { + location = tokens[1] + } traceable := TraceableError{ location: location, message: current.Error(), diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index 79560bc75..a34082e5f 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -22,7 +22,6 @@ import ( "strings" "sync" "testing" - "text/template" "github.com/stretchr/testify/assert" @@ -1291,16 +1290,11 @@ func TestRenderTplMissingKeyString(t *testing.T) { t.Errorf("Expected error, got %v", out) return } - switch err.(type) { - case (template.ExecError): - errTxt := fmt.Sprint(err) - if !strings.Contains(errTxt, "noSuchKey") { - t.Errorf("Expected error to contain 'noSuchKey', got %s", errTxt) - } - default: - // Some unexpected error. - t.Fatal(err) + errTxt := fmt.Sprint(err) + if !strings.Contains(errTxt, "noSuchKey") { + t.Errorf("Expected error to contain 'noSuchKey', got %s", errTxt) } + } func TestNestedHelpersProducesMultilineStacktrace(t *testing.T) {