fix: add some index checking and fixed a test that relied on type-checking

Signed-off-by: Jesse Simpson <jesse.simpson36@gmail.com>
pull/13586/head
Jesse Simpson 8 months ago
parent 80d7a1b33f
commit 98da3e28b6
No known key found for this signature in database
GPG Key ID: 237495C89AB0AAFC

@ -347,6 +347,9 @@ func (t TraceableError) ExtractExecutedFunction() (TraceableError, error) {
} }
byteArrayMsg := []byte(t.message) byteArrayMsg := []byte(t.message)
executionLocations := executionLocationRegex.FindAll(byteArrayMsg, -1) executionLocations := executionLocationRegex.FindAll(byteArrayMsg, -1)
if len(executionLocations) == 0 {
return t, nil
}
t.executedFunction = string(executionLocations[0]) t.executedFunction = string(executionLocations[0])
t.message = strings.ReplaceAll(t.message, t.executedFunction, "") t.message = strings.ReplaceAll(t.message, t.executedFunction, "")
return t, nil return t, nil
@ -422,7 +425,12 @@ func cleanupExecError(filename string, err error) error {
break break
} }
tokens = strings.SplitN(current.Error(), ": ", 3) 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{ traceable := TraceableError{
location: location, location: location,
message: current.Error(), message: current.Error(),

@ -22,7 +22,6 @@ import (
"strings" "strings"
"sync" "sync"
"testing" "testing"
"text/template"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -1291,16 +1290,11 @@ func TestRenderTplMissingKeyString(t *testing.T) {
t.Errorf("Expected error, got %v", out) t.Errorf("Expected error, got %v", out)
return return
} }
switch err.(type) { errTxt := fmt.Sprint(err)
case (template.ExecError): if !strings.Contains(errTxt, "noSuchKey") {
errTxt := fmt.Sprint(err) t.Errorf("Expected error to contain 'noSuchKey', got %s", errTxt)
if !strings.Contains(errTxt, "noSuchKey") {
t.Errorf("Expected error to contain 'noSuchKey', got %s", errTxt)
}
default:
// Some unexpected error.
t.Fatal(err)
} }
} }
func TestNestedHelpersProducesMultilineStacktrace(t *testing.T) { func TestNestedHelpersProducesMultilineStacktrace(t *testing.T) {

Loading…
Cancel
Save