{"record":{"id":"a0232b6c6b35f521","repo":"karatelabs/karate","slug":"image-write-failed-to-write-p-message","errorCode":null,"errorMessage":"image.write: failed to write '{p}': {message}","messagePattern":"image\\.write: failed to write '(.+?)': (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-image/src/main/java/io/karatelabs/ext/image/ImageApi.java","lineNumber":469,"sourceCode":"    private boolean resourceExists(String p) {\n        Resource r = resolveResource(p);\n        return r != null && r.exists();\n    }\n\n    private void writeBytes(String p, byte[] bytes) {\n        try {\n            Resource r = resolveResource(p);\n            java.nio.file.Path target = r != null ? r.getPath() : null;\n            if (target == null) {\n                target = new java.io.File(p).toPath();\n            }\n            java.nio.file.Path parent = target.getParent();\n            if (parent != null) {\n                java.nio.file.Files.createDirectories(parent);\n            }\n            java.nio.file.Files.write(target, bytes);\n        } catch (Exception e) {\n            throw new RuntimeException(\"image.write: failed to write '\" + p + \"': \" + e.getMessage(), e);\n        }\n    }\n\n    // ---- arg parsing + small helpers ----\n\n    private static Map<String, Object> parseArgs(Object... args) {\n        Map<String, Object> out = new LinkedHashMap<>();\n        if (args.length == 1 && args[0] instanceof Map<?, ?> map) {\n            map.forEach((k, v) -> out.put(String.valueOf(k), v));\n            return out;\n        }\n        if (args.length > 0) {\n            // a bare-name String → resolved baseline + <name> options; a path-looking String\n            // (this:/classpath:/file:/contains a slash) → explicit baseline; bytes → baseline\n            Object first = args[0];\n            if (first instanceof String s && !looksLikePath(s)) {\n                out.put(\"name\", s);\n            } else {","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-image/src/main/java/io/karatelabs/ext/image/ImageApi.java#L451-L487","documentation":"writeBytes writes image bytes to the target path, creating parent directories as needed. Any failure in directory creation or file writing (permissions, missing filesystem, IO error) is wrapped in a RuntimeException identifying the path and underlying message.","triggerScenarios":"Calling image.write (directly or via writeVerb) where the resolved target path's parent cannot be created or the file cannot be written — e.g. read-only report output dir, no space left on device, invalid path characters, or target inside a file (not directory).","commonSituations":"CI containers with a read-only workspace; report output dir deleted/replaced by a symlink mid-run; writing to /reports on a volume mounted read-only; disk quota exceeded on long suites; path containing illegal characters on Windows.","solutions":["Read the wrapped cause and path in the message; check whether the target directory exists and is writable","Fix permissions on the report output directory (chmod/chown or fix the mount as read-write)","Free disk space or raise the quota if the cause is no-space","If overriding the path explicitly, pass a valid absolute path in a writable location"],"exampleFix":"// before\nchmod 444 target/reports\nkarate.call('image.write', 'shot', bytes); // fails\n// after\nchmod 755 target/reports\nkarate.call('image.write', 'shot', bytes);","handlingStrategy":"try-catch","validationCode":"# karate\n* def outDir = karate.properties['karate.outputDir']\n* if (!karate.os.path(outDir)) karate.call('mkoutputdir', outDir) // ensure writable dir exists","typeGuard":null,"tryCatchPattern":"try { return karate.call('image.write', name, bytes); } catch (Exception e) { if (('' + e).startsWith('image.write: failed to write')) { karate.warn('write failed: ' + e.message); return null; } throw e; }","preventionTips":["Ensure the report output directory exists and is writable before the suite starts","Check disk space/quota in CI before long image suites","Avoid read-only mounts for the workspace","Use simple absolute paths without illegal characters"],"tags":["karate","image-comparison","file-write","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"}