{"record":{"id":"01dfba6967b8e195","repo":"karatelabs/karate","slug":"embed-needs-at-least-one-argument-data","errorCode":null,"errorMessage":"embed() needs at least one argument: data","messagePattern":"embed\\(\\) needs at least one argument: data","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java","lineNumber":503,"sourceCode":"    }\n\n    /**\n     * Embed content in the report. Two forms:\n     * <ul>\n     *   <li><b>Single-part (legacy):</b> {@code embed(data, mime?, name?)} — auto-detects MIME\n     *       when omitted.</li>\n     *   <li><b>Multi-part (object):</b> {@code embed({ name, parts:[{role, mime?, data|path|url}], meta })}\n     *       — for rich embeds (e.g. image-comparison). Dispatched when the first arg is a Map\n     *       carrying a {@code parts} list. Each part: {@code role} is required;\n     *       {@code data} (bytes / Uint8Array) or {@code path} (a resource string core reads to\n     *       bytes) or {@code url} (a report-relative asset the caller wrote); {@code mime} is\n     *       auto-detected from the bytes when omitted.</li>\n     * </ul>\n     */\n    JavaInvokable embed() {\n        return args -> {\n            if (args.length < 1) {\n                throw new RuntimeException(\"embed() needs at least one argument: data\");\n            }\n            Object first = unwrapJs(args[0]);\n            if (first instanceof Map<?, ?> map && map.get(\"parts\") instanceof List) {\n                LogContext.get().embed(toMultiPartEmbed(map));\n                return null;\n            }\n            // single-part (legacy)\n            String mimeType = args.length > 1 && args[1] != null\n                    ? args[1].toString() : KarateJsUtils.detectMimeType(first);\n            String name = args.length > 2 ? args[2].toString() : null;\n            byte[] data = KarateJsUtils.convertToBytes(first);\n            LogContext.get().embed(data, mimeType, name);\n            return null;\n        };\n    }\n\n    private StepResult.Embed toMultiPartEmbed(Map<?, ?> map) {\n        String name = map.get(\"name\") != null ? map.get(\"name\").toString() : null;","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java#L485-L521","documentation":"karate.embed() attaches content (bytes, a file path, or URL data) to the current step's report, and requires at least the data argument. Karate throws this when embed is called with zero arguments, as there is nothing to embed.","triggerScenarios":"`karate.embed()` called with no arguments from JS; an undefined variable passed where arity is checked before unwrapping.","commonSituations":"Building report attachments dynamically where the byte array failed to materialize; copying embed examples without arguments; calling embed conditionally when the variable wasn't set.","solutions":["Pass the content as the first argument: karate.embed(bytes) or karate.embed({parts: [...], ...}) for multipart embeds.","For file/report attachments, embed a byte array (e.g. from karate.readBytes or an HTTP response) or a map with parts entries.","Verify the variable holding the content is assigned before calling embed."],"exampleFix":"// before\nkarate.embed();\n\n// after\nvar bytes = karate.readBytes('classpath:screenshot.png');\nkarate.embed(bytes, 'image/png');","handlingStrategy":"validation","validationCode":"if (data == null) { throw new Error('embed content required'); } karate.embed(data, mime);","typeGuard":"function isEmbeddable(x) { return x instanceof Array || x instanceof Uint8Array || typeof x === 'string' || (x != null && typeof x === 'object'); }","tryCatchPattern":"try { karate.embed(bytes); } catch (e) { if (String(e.message).includes('needs at least one argument')) { karate.log('nothing to embed'); } throw e; }","preventionTips":["Assign content to a variable and check it before embed","Pass bytes directly or a multipart map with a parts list","Verify readBytes/HTTP calls succeeded before embedding their output"],"tags":["javascript","arguments","reporting","embed","karate"],"backgroundTag":"missing-required-argument","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"}