karatelabs/karate · error · RuntimeException
karate.callonce() requires at least one argument (feature…
Error message
karate.callonce() requires at least one argument (feature path)
What it means
karate.callonce() requires the path of the feature (or JS file) to call as its first argument. Karate throws this when callonce is invoked with zero arguments, since there is nothing to execute or cache.
Solutions
- Pass the feature path as the first argument, e.g. karate.callonce('classpath:shared.feature').
- If the path comes from a variable, verify it is non-null/non-empty before the call.
- If you intended to pass call arguments, supply them as the second argument: karate.callonce(path, arg).
Example fix
// before
karate.callonce();
// after
karate.callonce('classpath:shared/data.feature'); Defensive patterns
Strategy: validation
Validate before calling
if (!path || typeof path !== 'string') { throw new Error('callonce path required'); } karate.callonce(path); Type guard
function isValidPath(p) { return typeof p === 'string' && p.trim().length > 0; } Try / catch
try { karate.callonce(path); } catch (e) { if (String(e.message).includes('requires at least one argument')) { karate.log('missing feature path for callonce'); } throw e; } Prevention
- Always pass the feature path as the first argument
- Assert path variables are non-empty before use
- Review call signatures when refactoring call expressions
When it happens
Trigger: `karate.callonce()` with no arguments, or passing only an optional second argument without a path first.
Common situations: Refactoring call expressions and dropping the argument; dynamic path variable undefined at call time; copying callonce usage without its feature path.
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
- karate.callonce() is not available in this context
- karate.callSingle() requires at least one argument (path)
- configure() needs two arguments: key and value
- embed() needs at least one argument: data
- read() needs at least one argument
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/d9d0fb27e2d3ba93.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java:390
if (rt == null) {
throw new RuntimeException("karate.setupOnce() is not available in this context");
}
String name = args.length > 0 && args[0] != null ? args[0].toString() : null;
return rt.executeSetupOnce(name);
};
}
/**
* karate.callonce() - Execute a feature file once per feature and cache the result.
*/
JavaInvokable callonce() {
return args -> {
ScenarioRuntime rt = getRuntime();
if (rt == null) {
throw new RuntimeException("karate.callonce() is not available in this context");
}
if (args.length == 0) {
throw new RuntimeException("karate.callonce() requires at least one argument (feature path)");
}
String path = args[0].toString();
Object arg = args.length > 1 ? args[1] : null;
return rt.executeJsCallOnce(path, arg);
};
}
/**
* karate.callSingle() - Execute a feature/JS file once per Suite and cache the result.
*/
JavaInvokable callSingle() {
return args -> {
ScenarioRuntime rt = getRuntime();
if (rt == null) {
throw new RuntimeException("karate.callSingle() is not available in this context");
}
if (args.length == 0) {
throw new RuntimeException("karate.callSingle() requires at least one argument (path)");View on GitHub (pinned to a22eb90246)