karatelabs/karate · error · RuntimeException
pretty() needs one argument
Error message
pretty() needs one argument
What it means
pretty() is a Karate JS utility that pretty-prints a value: Maps/Lists via JSON formatting, XML Nodes via Xml.toString. It throws this error when called with zero arguments, since there is no value to format.
Solutions
- Pass the value to print: pretty(myMap), pretty(response), or pretty(xmlNode).
- If the value may be undefined, print a fallback string instead: pretty(variable || '(missing)').
- For plain XML strings prefer prettyXml(), which also accepts strings.
Example fix
// before print pretty() // after print pretty(response)
Defensive patterns
Strategy: type-guard
Validate before calling
if (response) { print pretty(response) } else { print '(no response)' } Prevention
- pretty() takes exactly one argument — the value to format.
- Use pretty() for JSON-shaped data and prettyXml() for XML.
- Bind the value to a named variable first, then print pretty(thatVariable).
When it happens
Trigger: karate.pretty() with no arguments, e.g. pretty() instead of pretty(response).
Common situations: Debug-printing in a Scenario and forgetting to pass the variable; the variable name was deleted during cleanup; copying karate.pretty from docs without adapting the argument.
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
- eval() needs one argument
- expect() needs at least one argument
- append() needs at least two arguments
- appendTo() needs at least two arguments: list and item(s)
- extract() needs three arguments: text, regex, group
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/e9bbf30f3b05fa98.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:392
static JavaInvokable pause() {
return args -> {
if (args.length == 0 || args[0] == null) {
return null;
}
long millis = ((Number) args[0]).longValue();
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return null;
};
}
static JavaInvokable pretty() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("pretty() needs one argument");
}
Object obj = args[0];
if (obj instanceof Map || obj instanceof List) {
return StringUtils.formatJson(obj);
} else if (obj instanceof Node) {
return Xml.toString((Node) obj, true);
} else {
return obj != null ? obj.toString() : "null";
}
};
}
/**
* Generate a range of integers.
* Usage: karate.range(0, 5) => [0, 1, 2, 3, 4]
* karate.range(0, 10, 2) => [0, 2, 4, 6, 8]
* karate.range(5, 0, -1) => [5, 4, 3, 2, 1]
*/View on GitHub (pinned to a22eb90246)