Skip to content

Commit ebc0969

Browse files
committed
Debugging panic attribution
1 parent 529f218 commit ebc0969

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/flakeguard/runner/runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,25 +412,29 @@ func parseTestResults(filePaths []string) ([]reports.TestResult, error) {
412412
func attributePanicToTest(panicPackage string, panicEntries []entry) (string, error) {
413413
regexSanitizePanicPackage := filepath.Base(panicPackage)
414414
panicAttributionRe := regexp.MustCompile(fmt.Sprintf(`%s\.(Test[^\.\(]+)`, regexSanitizePanicPackage))
415+
entriesOutputs := []string{}
415416
for _, entry := range panicEntries {
417+
entriesOutputs = append(entriesOutputs, entry.Output)
416418
if matches := panicAttributionRe.FindStringSubmatch(entry.Output); len(matches) > 1 {
417419
return matches[1], nil
418420
}
419421
}
420-
return "", fmt.Errorf("failed to attribute panic to test, using regex %s on '%s'", panicAttributionRe.String(), regexSanitizePanicPackage)
422+
return "", fmt.Errorf("failed to attribute panic to test, using regex %s on these strings:\n%s", panicAttributionRe.String(), strings.Join(entriesOutputs, "\n"))
421423
}
422424

423425
// properly attributes races to the test that caused them
424426
// Go JSON output gets confused, especially when tests are run in parallel
425427
func attributeRaceToTest(racePackage string, raceEntries []entry) (string, error) {
426428
regexSanitizeRacePackage := filepath.Base(racePackage)
427429
raceAttributionRe := regexp.MustCompile(fmt.Sprintf(`%s\.(Test[^\.\(]+)`, regexSanitizeRacePackage))
430+
entriesOutputs := []string{}
428431
for _, entry := range raceEntries {
432+
entriesOutputs = append(entriesOutputs, entry.Output)
429433
if matches := raceAttributionRe.FindStringSubmatch(entry.Output); len(matches) > 1 {
430434
return matches[1], nil
431435
}
432436
}
433-
return "", fmt.Errorf("failed to attribute race to test, using regex: %s on '%s'", raceAttributionRe.String(), regexSanitizeRacePackage)
437+
return "", fmt.Errorf("failed to attribute race to test, using regex: %s on these strings:\n%s", raceAttributionRe.String(), strings.Join(entriesOutputs, "\n"))
434438
}
435439

436440
// parseSubTest checks if a test name is a subtest and returns the parent and sub names

0 commit comments

Comments
 (0)