fix: include filename in JUnit XML parse errors and consolidate directory walk#895
Conversation
Replace junit.IngestDir() with our own filepath.Walk that calls junit.IngestFile() per file and wraps errors with the filename. This makes XML parsing errors actionable — users can now see which file caused the failure. Add test fixture with ISO-8859-15 encoding declaration and three unit tests for ingestJunitDir: filename in error, no-tests-found, and valid JUnit parsing. Refs #894
Same wrapping treatment as ingestJunitDir — wrap junit.IngestFile() errors with the filename so users can identify which file caused the failure. Refs #894
ingestJunitDir now returns both parsed results and the list of JUnit filenames (for upload), eliminating the separate getJunitFilenames() function and its redundant directory walk. Refs #894
|
Claude finished @dangrondahl's task in 3m 25s —— View job PR Review: fix: include filename in JUnit XML parse errors and consolidate directory walk
Static AnalysisAll three checks pass cleanly: SummaryThis PR is in good shape. The core change — consolidating the double directory walk into a single pass and wrapping parse errors with the filename — is clean, correct, and well-tested. No bugs or security issues found. What's done well
Minor observations (all optional, no blockers)
No blocking issues. Looks ready to merge. |
Benchmark: single-pass vs double-pass directory walkMeasured on
The ratio stays constant regardless of file count since both walks do identical per-file work (walk + open + XML decode). The real-world impact scales with the number of |
- Return nil instead of empty slice on Walk error for consistency - Merge TestIngestJunitDir_ReturnsFilenames into TestIngestJunitDir Refs #894
|
Re: the suggestion to move This is intentionally placed outside Applied the other two suggestions (return |
Replace the cryptic Go stdlib error (Decoder.CharsetReader is nil) with an actionable message that tells the user which file failed, that only UTF-8 is supported, and to use --results-dir if the file is not a JUnit results file. Refs #894
- Use filepath.WalkDir instead of filepath.Walk (avoids os.Lstat per entry) - Return nil, nil on all error paths for consistency - Assert exact filename count in test Refs #894
Benchmark:
|
| Metric | Walk |
WalkDir |
Delta |
|---|---|---|---|
| Time | ~2.9 ms | ~2.75 ms | ~5% faster |
| Allocs | 24,951 | 24,831 | 120 fewer |
| Memory | 3.22 MB | 3.20 MB | ~22 KB less |
The savings come from WalkDir skipping the os.Lstat call per directory entry. The improvement would be more pronounced in larger directory trees with many non-XML files, where the stat is wasted entirely — relevant when --results-dir defaults to . and the CLI walks the entire repo.
Summary
kosli attest junitnow includes the filename and a user-friendly message when XML parsing fails, making errors actionable instead of crypticBefore:
After:
Changes
junit.IngestDir()with our ownfilepath.Walkthat callsjunit.IngestFile()per file and wraps errors with the filenameingestJunitDirnow returns both parsed results and the list of JUnit filenames in a single passgetJunitFilenames()— its work is folded into the single walkingestJunitDirDecision: no charset support (Fix 2 dropped)
We considered adding
golang.org/x/net/html/charsetto handle non-UTF-8 XML encodings transparently. We decided against it because:.xmlfiles in--results-dir(default.), so non-JUnit XML files (pom.xml, config files) get parsed too--results-dirto narrow scope, and the error message now guides them to do thatCloses #894