refactor: prevent duplicates being inserted rather than post-filtering

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

@ -379,6 +379,9 @@ func cleanupExecError(filename string, err error) error {
if current == nil { if current == nil {
break break
} }
if i == maxIterations-1 {
return err
}
var traceable TraceableError var traceable TraceableError
if execErrFmt.MatchString(current.Error()) { if execErrFmt.MatchString(current.Error()) {
@ -409,34 +412,24 @@ func cleanupExecError(filename string, err error) error {
} else { } else {
return err return err
} }
fileLocations = append(fileLocations, traceable) if len(fileLocations) > 0 {
lastErr := fileLocations[len(fileLocations)-1]
if lastErr.message == traceable.message &&
lastErr.location == traceable.location &&
lastErr.executedFunction == traceable.executedFunction {
current = errors.Unwrap(current) current = errors.Unwrap(current)
}
if current != nil {
return err
}
var prev TraceableError
for i := len(fileLocations) - 1; i >= 0; i-- {
current := fileLocations[i]
if i == len(fileLocations)-1 {
prev = current
continue continue
} }
if current.message == prev.message && current.location == prev.location && current.executedFunction == prev.executedFunction {
fileLocations[i].message = ""
} }
prev = current fileLocations = append(fileLocations, traceable)
current = errors.Unwrap(current)
} }
finalErrorString := "" finalErrorString := ""
for _, fileLocation := range fileLocations { for _, fileLocation := range fileLocations {
if fileLocation.message == "" {
continue
}
finalErrorString = finalErrorString + fileLocation.String() finalErrorString = finalErrorString + fileLocation.String()
} }
if strings.TrimSpace(finalErrorString) == "" { if strings.TrimSpace(finalErrorString) == "" {
// Fallback to original error message if nothing was extracted // Fallback to original error message if nothing was extracted
return err return err

Loading…
Cancel
Save