{"record":{"id":"e915146f71c85bbb","repo":"karatelabs/karate","slug":"embed-each-parts-entry-must-be-an-object","errorCode":null,"errorMessage":"embed(): each 'parts' entry must be an object","messagePattern":"embed\\(\\): each 'parts' entry must be an object","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java","lineNumber":526,"sourceCode":"                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;\n        List<StepResult.Part> parts = new ArrayList<>();\n        for (Object partObj : (List<?>) map.get(\"parts\")) {\n            Object pu = unwrapJs(partObj);\n            if (!(pu instanceof Map<?, ?> pm)) {\n                throw new RuntimeException(\"embed(): each 'parts' entry must be an object\");\n            }\n            Object roleObj = pm.get(\"role\");\n            if (roleObj == null) {\n                throw new RuntimeException(\"embed(): each part needs a 'role'\");\n            }\n            String role = roleObj.toString();\n            String mime = pm.get(\"mime\") != null ? pm.get(\"mime\").toString() : null;\n            Object url = pm.get(\"url\");\n            if (url != null) {\n                parts.add(new StepResult.Part(role, mime, url.toString()));\n                continue;\n            }\n            byte[] bytes;\n            Object dataObj = pm.get(\"data\");\n            Object pathObj = pm.get(\"path\");\n            if (dataObj != null) {\n                bytes = KarateJsUtils.convertToBytes(unwrapJs(dataObj));\n            } else if (pathObj != null) {","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java#L508-L544","documentation":"When karate.embed() receives a multipart embed object ({parts: [...]}), every entry of the parts list must itself be an object describing a part (role, data/path/url, optional mime). Karate throws this when a parts entry is a string, number, array, or null instead of a map.","triggerScenarios":"karate.embed({ name: ..., parts: ['screenshot.png'] }) or parts entries that are plain strings / null / nested lists instead of objects with role and content fields.","commonSituations":"Assuming parts can be plain file paths; building the parts list programmatically and pushing raw paths; JSON structures where entries ended up as strings after templating.","solutions":["Wrap each entry as an object: karate.embed({parts: [{role: 'screenshot', path: 'shot.png'}]}).","Validate each part object has a role plus one of data/path/url before calling embed.","If embedding a single item, pass the bytes directly instead of a parts list."],"exampleFix":"// before\nkarate.embed({ parts: ['shot.png'] });\n\n// after\nkarate.embed({ parts: [{ role: 'image', path: 'shot.png' }] });","handlingStrategy":"validation","validationCode":"if (parts.some(function(p){ return p == null || typeof p !== 'object' || Array.isArray(p); })) { throw new Error('each part must be an object'); }","typeGuard":"function isEmbedPart(p) { return p != null && typeof p === 'object' && !Array.isArray(p); }","tryCatchPattern":"try { karate.embed({ parts: parts }); } catch (e) { if (String(e.message).includes(\"each 'parts' entry must be an object\")) { karate.log('invalid parts entry'); } throw e; }","preventionTips":["Wrap file paths in part objects instead of passing raw strings","Validate the parts array shape before calling embed","Prefer single-content embed (bytes) when multipart structure is not needed"],"tags":["javascript","validation","embed","reporting","karate"],"backgroundTag":"invalid-argument-format","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"}