{"record":{"id":"fb966a5116ef352d","repo":"karatelabs/karate","slug":"doc-called-but-no-destination-set","errorCode":null,"errorMessage":"doc() called, but no destination set","messagePattern":"doc\\(\\) called, but no destination set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":167,"sourceCode":"     * Called by the 'doc' keyword in StepExecutor.\n     */\n    public String doc(Map<String, Object> options) {\n        String read = (String) options.get(\"read\");\n        if (read == null) {\n            throw new RuntimeException(\"doc() requires 'read' key with template path\");\n        }\n        String html = markup().processPath(read, null);\n        if (onDoc != null) {\n            onDoc.accept(html);\n        }\n        return html;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private JavaInvokable doc() {\n        return args -> {\n            if (onDoc == null) {\n                logger.warn(\"doc() called, but no destination set\");\n                return null;\n            }\n            if (args.length == 0) {\n                throw new RuntimeException(\"doc() needs at least one argument\");\n            }\n            String read;\n            if (args[0] instanceof Map) {\n                Map<String, Object> map = (Map<String, Object>) args[0];\n                read = (String) map.get(\"read\");\n            } else if (args[0] == null) {\n                read = null;\n            } else {\n                read = args[0] + \"\";\n            }\n            if (read == null) {\n                throw new RuntimeException(\"doc() read arg should not be null\");\n            }\n            Map<String, Object> vars;","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L149-L185","documentation":"karate.doc() in the JS engine logs this warning when invoked before any doc-rendering sink (onDoc callback) has been registered by the host runtime. In karate-core's KarateJs, the doc() invokable is always available in JS scope, but it only has a destination when an embed/reporting listener is attached (e.g. a UI or report renderer). Without one, the call is a no-op: a warning is logged and null is returned instead of throwing.","triggerScenarios":"Calling `karate.doc(...)` (or the `doc()` JS function) inside a scenario/JS block while running in a context where no onDoc callback was set on the KarateJs instance — e.g. headless/plain JVM embedding without a doc destination, or a custom runner that builds KarateJs directly and never registers a doc sink.","commonSituations":"Running V2 Karate via a custom embedded runner or test harness that did not wire up reporting; copying V1 feature code that used doc/embed-style output into an environment without a doc consumer; calling doc() from a background/JS utility where the reporting hook is not attached.","solutions":["Register a doc destination on the KarateJs instance before running (set the onDoc callback / use the standard runner that wires reporting).","Remove or guard the karate.doc(...) call if you do not need the rendered output in this run mode.","Check whether you are using a custom/embedded runner instead of the standard one; switch to the standard runner so the doc sink is configured automatically.","Treat the warning as benign if doc output is intentionally unsupported in this context — the call returns null safely."],"exampleFix":"// before (custom runner, no doc sink)\nKarateJs js = new KarateJs(context);\njs.eval(\"karate.doc('some text')\"); // warns: no destination set\n\n// after — provide a destination\nKarateJs js = new KarateJs(context);\njs.onDoc(doc -> { log.info(\"doc: {}\", doc); return null; });\njs.eval(\"karate.doc('some text')\");","handlingStrategy":"fallback","validationCode":"// JS: check a marker set by your runner before using doc\nif (typeof karate.doc === 'function') {\n  karate.doc('report text');\n}","typeGuard":"function canDoc(karate) { return typeof karate.doc === 'function'; }","tryCatchPattern":"// doc() returns null instead of throwing; handle the null result\nvar rendered = karate.doc('text');\nif (rendered === null) { /* doc sink not configured; skip or log */ }","preventionTips":["Use the standard Karate runner so the doc/report sink is wired automatically.","In custom runners, always register the onDoc callback on KarateJs before eval.","Keep doc/output calls out of shared utility JS that runs in non-reporting contexts."],"tags":["javascript","reporting","karate","no-op"],"backgroundTag":"missing-dependency","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"}