{"record":{"id":"810a4081e5744d7e","repo":"karatelabs/karate","slug":"doc-needs-at-least-one-argument","errorCode":null,"errorMessage":"doc() needs at least one argument","messagePattern":"doc\\(\\) needs at least one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":171,"sourceCode":"        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;\n            if (args.length > 1) {\n                vars = (Map<String, Object>) args[1];\n            } else {\n                vars = null;","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L153-L189","documentation":"The JS-exposed doc() function accepts variable arguments; when invoked with zero arguments there is no template path to render, so it throws. (It also no-ops with a warning if no onDoc destination is set, but with a destination set, zero args is an error.)","triggerScenarios":"Calling doc() with no arguments at all from JS, e.g. karate.doc() — usually from generated or scripted code where arguments were meant to be passed through but weren't.","commonSituations":"A wrapper function forgetting to forward its arguments to doc(); dynamic argument construction that produced an empty array; misuse of doc as a flag rather than a rendering call.","solutions":["Pass at least the template path: karate.doc('classpath:doc/template.html')","If forwarding from a wrapper, spread the arguments: (...args) => karate.doc(...args)","If the intent was only to check rendering setup, remove the call — a no-op destination already logs a warning"],"exampleFix":"// before\nfunction renderDoc() { return karate.doc(); }\n// after\nfunction renderDoc(path, vars) { return karate.doc(path, vars); }","handlingStrategy":"validation","validationCode":"if (arguments.length === 0) { throw 'doc() needs a template path argument'; }","typeGuard":"function canCallDoc(args) { return args && args.length >= 1; }","tryCatchPattern":"try { karate.doc.apply(null, args); } catch (RuntimeException e) { if (e.getMessage().contains('needs at least one argument')) { log.error('forward args from wrappers'); } throw e; }","preventionTips":["Forward varargs in wrapper functions (…args)","Never call doc() bare; always pass a path","Lint JS helpers for unforwarded arguments"],"tags":["doc","missing-argument","javascript","arity"],"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"}