karatelabs/karate · warning
Failed to write JUnit XML for
Error message
Failed to write JUnit XML for {}: {} What it means
JunitXmlReportListener.onFeatureEnd() writes each feature's JUnit XML inline as the feature completes. Any exception during serialization or file writing is caught and logged with the feature display name, so one feature's report failure never aborts the suite.
Solutions
- Ensure the output directory exists and is writable for the whole suite duration
- Check disk space/quota on the target volume
- Enable debug logging to capture the underlying exception stack
- If serialization-specific, inspect that feature's result data (e.g. unusual characters in display name) and update Karate if a bug
Defensive patterns
Strategy: try-catch
Validate before calling
if (!Files.isDirectory(outputDir) || !Files.isWritable(outputDir))
throw new IllegalStateException("JUnit XML output dir not writable: " + outputDir);
if (Files.getUsableSpace(outputDir) < 50_000_000)
logger.warn("low disk space for JUnit XML output"); Try / catch
try {
JunitXmlWriter.writeSerialized(JunitXmlWriter.fileNameFor(result),
JunitXmlWriter.serializeFeature(result), outputDir);
} catch (Exception e) {
logger.warn("Failed to write JUnit XML for {}: {}", result.getDisplayName(), e.getMessage(), e);
} Prevention
- Pre-create and lock the output directory for the suite duration (avoid concurrent clean tasks)
- Monitor disk quota on CI agents
- Log full stack traces when diagnosing per-feature write failures
When it happens
Trigger: Exception from JunitXmlWriter.writeSerialized(...) — output directory missing/unwritable, disk full, or serialization error on the FeatureResult for that specific feature.
Common situations: Output directory removed mid-run by a clean task; permission issues on CI; a feature result containing data that breaks XML serialization; disk quota exceeded.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Failed to write JUnit XML for
- Failed to copy static resources
- Failed to write HTML report
- Failed to externalize embeds
- Failed to copy ext assets for
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/c0e3b2f295685852.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/output/JunitXmlReportListener.java:89
logger.warn("Failed to create JUnit XML output directory: {}", e.getMessage());
}
}
@Override
public void onFeatureEnd(FeatureResult result) {
// Sort scenarios for deterministic ordering
result.sortScenarioResults();
// Serialize AND write here, on the feature's own thread. The write used to be handed
// to a single-thread executor with an unbounded queue; measured over a many-feature
// suite that thread was idle — its share of the work was a few percent of wall-clock —
// so the queue could only ever grow, never help. Writing inline also means a feature
// cannot complete until its report is on disk, which bounds what is held in memory.
try {
JunitXmlWriter.writeSerialized(JunitXmlWriter.fileNameFor(result),
JunitXmlWriter.serializeFeature(result), outputDir);
} catch (Exception e) {
logger.warn("Failed to write JUnit XML for {}: {}", result.getDisplayName(), e.getMessage());
}
}
}
View on GitHub (pinned to a22eb90246)