{"record":{"id":"28824cee159af08f","repo":"karatelabs/karate","slug":"embed-failed-to-read-part-path-path-message","errorCode":null,"errorMessage":"embed(): failed to read part path '{path}': {message}","messagePattern":"embed\\(\\): failed to read part path '(.+?)': (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java","lineNumber":562,"sourceCode":"            } else if (pathObj != null) {\n                bytes = readPathBytes(pathObj.toString());\n            } else {\n                throw new RuntimeException(\"embed(): part '\" + role + \"' needs 'data', 'path', or 'url'\");\n            }\n            parts.add(new StepResult.Part(role, mime != null ? mime : KarateJsUtils.detectMimeType(bytes), bytes));\n        }\n        Object meta = map.get(\"meta\");\n        @SuppressWarnings(\"unchecked\")\n        Map<String, Object> metaMap = meta instanceof Map ? (Map<String, Object>) meta : null;\n        return new StepResult.Embed(name, parts, metaMap);\n    }\n\n    /** Read an embed part's {@code path} (this:/classpath:/file:/relative) into bytes. */\n    private byte[] readPathBytes(String path) {\n        try (java.io.InputStream is = getCurrentResource().resolve(path).getStream()) {\n            return is.readAllBytes();\n        } catch (Exception e) {\n            throw new RuntimeException(\"embed(): failed to read part path '\" + path + \"': \" + e.getMessage(), e);\n        }\n    }\n\n    /** Unwrap a JsValue (e.g. a nested Uint8Array / object) to its idiomatic Java value. */\n    private static Object unwrapJs(Object o) {\n        return o instanceof JsValue jv ? jv.getJavaValue() : o;\n    }\n\n    /**\n     * karate.signal() - Signal a result for listen/listenResult.\n     */\n    JavaInvokable signal() {\n        return args -> {\n            ScenarioRuntime rt = getRuntime();\n            if (rt != null && args.length > 0) {\n                rt.setListenResult(args[0]);\n            }\n            return null;","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java#L544-L580","documentation":"Karate's embed() JS bridge reads each part's path from disk via readPathBytes() in KarateJsBase. When resolving or reading the stream fails (missing file, bad scheme prefix, IO error), the raw exception is wrapped in this RuntimeException so the failing path and underlying message are surfaced to script authors.","triggerScenarios":"Calling embed(path) (or embed with multiple parts) in JS where a part path cannot be resolved by the current Resource against getCurrentResource().resolve(path), or whose InputStream cannot be opened/read: nonexistent file, wrong this:/classpath:/file: prefix, unreadable file, or empty/corrupt target.","commonSituations":"Typos in the report-embed path; embedding a classpath resource that was never packaged into the jar/test classpath; using a relative path when the working directory differs between local runs and CI; file moved after generation (e.g. screenshot not yet written).","solutions":["Verify the path exists relative to the feature file / current resource and fix typos","Check the URI prefix: use this: for feature-relative, classpath: for packaged resources, file: for absolute paths","Ensure classpath resources are actually on the test classpath (target/test-classes, jar packaging)","Inspect the wrapped cause message ({message}) for the underlying IO error and fix permissions or disk issues"],"exampleFix":"// before\nembed('screenshots/login.png')\n// after\n// file is feature-relative, or generate it before embedding\nvar path = 'classpath:reports/login.png';\nif (karate.readIfExists) { /* or ensure the file exists */ }\nembed('this:reports/login.png');","handlingStrategy":"try-catch","validationCode":"function fileExists(p) { return java.nio.file.Files.exists(java.nio.file.Paths.get(p)); } // or karate.readIfExists for classpath","typeGuard":null,"tryCatchPattern":"try { embed(path); } catch (e) { karate.log('embed failed for ' + path + ': ' + e.message); }","preventionTips":["Always use this:/classpath: prefixes explicitly rather than bare relative paths","Generate files (screenshots, reports) before calling embed()","Verify resource packaging (classpath entries) in CI before test runs"],"tags":["file-io","embed","resource-resolution","karate"],"backgroundTag":"file-read-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"}