karatelabs/karate · error · RuntimeException
doc() needs at least one argument
Error message
doc() needs at least one argument
What it means
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.)
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
Example fix
// before
function renderDoc() { return karate.doc(); }
// after
function renderDoc(path, vars) { return karate.doc(path, vars); } Defensive patterns
Strategy: validation
Validate before calling
if (arguments.length === 0) { throw 'doc() needs a template path argument'; } Type guard
function canCallDoc(args) { return args && args.length >= 1; } Try / catch
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; } Prevention
- Forward varargs in wrapper functions (…args)
- Never call doc() bare; always pass a path
- Lint JS helpers for unforwarded arguments
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- doc() requires 'read' key with template path
- doc() read arg should not be null
- karate.match() needs at least one argument
- karate.call() requires at least one argument (feature path)
- karate.call() with sharedScope requires a feature path
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/810a4081e5744d7e.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJs.java:171
if (read == null) {
throw new RuntimeException("doc() requires 'read' key with template path");
}
String html = markup().processPath(read, null);
if (onDoc != null) {
onDoc.accept(html);
}
return html;
}
@SuppressWarnings("unchecked")
private JavaInvokable doc() {
return args -> {
if (onDoc == null) {
logger.warn("doc() called, but no destination set");
return null;
}
if (args.length == 0) {
throw new RuntimeException("doc() needs at least one argument");
}
String read;
if (args[0] instanceof Map) {
Map<String, Object> map = (Map<String, Object>) args[0];
read = (String) map.get("read");
} else if (args[0] == null) {
read = null;
} else {
read = args[0] + "";
}
if (read == null) {
throw new RuntimeException("doc() read arg should not be null");
}
Map<String, Object> vars;
if (args.length > 1) {
vars = (Map<String, Object>) args[1];
} else {
vars = null;View on GitHub (pinned to a22eb90246)