karatelabs/karate · error · RuntimeException
karate.call() with sharedScope requires a feature path
Error message
karate.call() with sharedScope requires a feature path
What it means
When the first argument to karate.call() is a Boolean it is treated as the sharedScope flag, so a second argument holding the feature path is mandatory. The code detects args[0] instanceof Boolean, finds args.length < 2, and throws. This guards the signature karate.call(sharedScope, path[, arg]) against a missing path.
Solutions
- Supply the feature path as the second argument: karate.call(true, 'classpath:x.feature') or karate.call(false, path, arg).
- If you only have a path (no scope flag), use the simple form karate.call(path[, arg]) instead.
- Verify the path argument isn't undefined/null at the call site; a dropped path leaves only the boolean.
- In wrapper functions, validate argument count before forwarding to karate.call.
Example fix
// before
karate.call(true);
// after
karate.call(true, 'classpath:helpers/shared.feature', { token: token }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof sharedScope === 'boolean' && (typeof path !== 'string' || path.length === 0)) {
throw new Error('karate.call(sharedScope, path) needs a feature path');
}
karate.call(sharedScope, path, arg); Type guard
function argsValidForCall(args) {
if (typeof args[0] === 'boolean') return args.length >= 2 && typeof args[1] === 'string' && args[1].length > 0;
return typeof args[0] === 'string' && args[0].length > 0;
} Try / catch
var result;
try {
result = karate.call(sharedScope, path, arg);
} catch (e) {
if (String(e.message).includes('with sharedScope requires a feature path')) {
throw new Error('path argument missing; signature is karate.call(sharedScope, path[, arg])');
}
throw e;
} Prevention
- Keep the two signatures straight: karate.call(path[, arg]) vs karate.call(sharedScope, path[, arg]) — when adding the boolean, shift the path right.
- Check that the path variable is not undefined; a null/undefined path silently leaves only the boolean in the argument list.
- In wrapper functions, validate the full argument tuple before forwarding to karate.call.
When it happens
Trigger: Calling karate.call(true) or karate.call(false) without the feature path — commonly from a dynamic call site where the path variable was undefined/null, so only the boolean made it into the argument list, or a spread where the path element was dropped.
Common situations: Refactors switching between the (path) and (sharedScope, path) signatures and forgetting to shift the path argument; wrapper functions that forward arguments and drop the second one; path variables that evaluate to undefined.
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.match() needs at least one argument
- karate.call() requires at least one argument (feature path)
- doc() requires 'read' key with template path
- doc() needs at least one argument
- fork() needs at least one argument
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/d996dcbde4d1a912.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJs.java:706
ScenarioRuntime rt = getRuntime();
if (rt == null) {
throw new RuntimeException("karate.call() is not available in this context");
}
if (args.length == 0) {
throw new RuntimeException("karate.call() requires at least one argument (feature path)");
}
// V1 compatible signatures:
// call(path) - isolated scope
// call(path, arg) - isolated scope with arg
// call(sharedScope, path) - explicit scope
// call(sharedScope, path, arg) - explicit scope with arg
boolean sharedScope = false;
String path;
Object arg;
if (args[0] instanceof Boolean) {
sharedScope = (Boolean) args[0];
if (args.length < 2) {
throw new RuntimeException("karate.call() with sharedScope requires a feature path");
}
path = args[1].toString();
arg = args.length > 2 ? args[2] : null;
} else {
path = args[0].toString();
arg = args.length > 1 ? args[1] : null;
}
Object result = rt.executeJsCall(path, arg);
if (sharedScope && result instanceof Map) {
// Merge result variables into current scope (only meaningful for single-call results)
@SuppressWarnings("unchecked")
Map<String, Object> resultMap = (Map<String, Object>) result;
for (var entry : resultMap.entrySet()) {
engine.put(entry.getKey(), entry.getValue());
}
}
return result;
};View on GitHub (pinned to a22eb90246)