{"record":{"id":"c0e3b2f295685852","repo":"karatelabs/karate","slug":"failed-to-write-junit-xml-for","errorCode":null,"errorMessage":"Failed to write JUnit XML for {}: {}","messagePattern":"Failed to write JUnit XML for (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/output/JunitXmlReportListener.java","lineNumber":89,"sourceCode":"            logger.warn(\"Failed to create JUnit XML output directory: {}\", e.getMessage());\n        }\n    }\n\n    @Override\n    public void onFeatureEnd(FeatureResult result) {\n        // Sort scenarios for deterministic ordering\n        result.sortScenarioResults();\n\n        // Serialize AND write here, on the feature's own thread. The write used to be handed\n        // to a single-thread executor with an unbounded queue; measured over a many-feature\n        // suite that thread was idle — its share of the work was a few percent of wall-clock —\n        // so the queue could only ever grow, never help. Writing inline also means a feature\n        // cannot complete until its report is on disk, which bounds what is held in memory.\n        try {\n            JunitXmlWriter.writeSerialized(JunitXmlWriter.fileNameFor(result),\n                    JunitXmlWriter.serializeFeature(result), outputDir);\n        } catch (Exception e) {\n            logger.warn(\"Failed to write JUnit XML for {}: {}\", result.getDisplayName(), e.getMessage());\n        }\n    }\n\n}\n","sourceCodeStart":71,"sourceCodeEnd":94,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/output/JunitXmlReportListener.java#L71-L94","documentation":"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.","triggerScenarios":"Exception from JunitXmlWriter.writeSerialized(...) — output directory missing/unwritable, disk full, or serialization error on the FeatureResult for that specific feature.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!Files.isDirectory(outputDir) || !Files.isWritable(outputDir))\n    throw new IllegalStateException(\"JUnit XML output dir not writable: \" + outputDir);\nif (Files.getUsableSpace(outputDir) < 50_000_000)\n    logger.warn(\"low disk space for JUnit XML output\");","typeGuard":null,"tryCatchPattern":"try {\n    JunitXmlWriter.writeSerialized(JunitXmlWriter.fileNameFor(result),\n            JunitXmlWriter.serializeFeature(result), outputDir);\n} catch (Exception e) {\n    logger.warn(\"Failed to write JUnit XML for {}: {}\", result.getDisplayName(), e.getMessage(), e);\n}","preventionTips":["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"],"tags":["junit-xml","filesystem","reporting"],"backgroundTag":"file-write-failed","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}