{"record":{"id":"8f78eeaf00aeb02b","repo":"karatelabs/karate","slug":"failed-to-externalize-embeds","errorCode":null,"errorMessage":"Failed to externalize embeds: {}","messagePattern":"Failed to externalize embeds: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/output/HtmlReportWriter.java","lineNumber":269,"sourceCode":"            Files.write(embedsDir.resolve(fileName), part.getData());\n            part.setFileName(fileName);\n        }\n    }\n\n    /**\n     * Externalize a feature result's inline-bytes embeds to {@code <outputDir>/embeds/} and set each\n     * part's {@code fileName}, so EVERY downstream serializer — the JSONL event stream <em>and</em> the\n     * HTML data JSON — references the file rather than inlining base64 (large screenshots stay on disk,\n     * the report still works off a folder / {@code file://}). Called from the {@code FEATURE_EXIT} seam\n     * ({@code Suite.fireEvent}) before any listener serializes the result; idempotent (a part with a\n     * fileName is skipped), so the HTML writer's later pass numbers each embed exactly once. Best-effort\n     * — a write failure never breaks the run. JSON evidence stays inline (see {@link #writeEmbedFile}).\n     */\n    public static void externalizeEmbeds(FeatureResult result, Path outputDir) {\n        try {\n            writeEmbedFiles(result, outputDir.resolve(\"embeds\"));\n        } catch (IOException e) {\n            logger.warn(\"Failed to externalize embeds: {}\", e.getMessage());\n        }\n    }\n\n    /**\n     * Write embed files to the embeds/ directory.\n     * Sets the fileName on each Embed for JSON serialization.\n     */\n    private static void writeEmbedFiles(FeatureResult result, Path embedsDir) throws IOException {\n        if (!hasEmbeds(result)) {\n            return;  // No embeds to write\n        }\n\n        Files.createDirectories(embedsDir);\n        for (ScenarioResult sr : result.getScenarioResults()) {\n            // @report=false scenarios suppress all step detail in toJson(); skip\n            // embed extraction so screenshots / attachments don't leak to disk either.\n            if (sr.isReportDisabled()) continue;\n            for (StepResult step : sr.getStepResults()) {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/output/HtmlReportWriter.java#L251-L287","documentation":"externalizeEmbeds() moves large embedded content (images, JSON attachments) out of the feature-result JSON into an embeds/ directory. Any IOException while writing those files is logged as a warning; the original JSON evidence stays inline, so data is not lost — only the lighter report layout is not achieved.","triggerScenarios":"IOException from writeEmbedFiles(result, outputDir.resolve(\"embeds\")) — e.g. the embeds directory cannot be created, a permission error, or disk full while writing embed payloads.","commonSituations":"Output directory on a full or read-only volume; embeds produced by large response bodies or many screenshots exhausting inodes/space; outputDir cleaned concurrently by another process.","solutions":["Check the output directory is writable and has free space before the run","Reduce embed volume (smaller screenshots, truncate large bodies) if disk pressure is the cause","Enable debug logging to capture the underlying IOException's full detail","Re-run; since JSON stays inline, verify report completeness — this warning alone need not block the pipeline"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"Path embeds = outputDir.resolve(\"embeds\");\nif (!Files.isWritable(outputDir)) throw new IllegalStateException(\"output dir not writable: \" + outputDir);\nFiles.createDirectories(embeds); // fail early, before the run","typeGuard":null,"tryCatchPattern":"try {\n    writeEmbedFiles(result, outputDir.resolve(\"embeds\"));\n} catch (IOException e) {\n    logger.warn(\"Failed to externalize embeds: {}\", e.getMessage()); // JSON stays inline\n}","preventionTips":["Ensure ample disk space where large embeds (screenshots, bodies) are expected","Remember embeds remain inline in JSON on failure — validate report completeness, don't just check for the warning","Pre-create the embeds directory in test setup"],"tags":["reporting","filesystem","embeds","io"],"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"}