karatelabs/karate · error · RuntimeException
karate.call() is not available in this context
Error message
karate.call() is not available in this context
What it means
karate.call() must run against a ScenarioRuntime: it delegates to rt.executeJsCall(path, arg) to invoke another feature/script. The bridge's getRuntime() returned null, meaning this karate object was created without a runtime binding, so calling another feature is impossible. The argument check comes after this check, so a context-less runtime is reported first.
Solutions
- Ensure karate.call() is only used inside a Scenario (or Background) where a ScenarioRuntime is active.
- In mock contexts, implement the behavior directly in JS or use mock-specific request/response handling instead of calling features.
- If the bridge should have a runtime, verify how the karate object was obtained — it must come from within scenario execution, not a detached engine.
Example fix
// before (in mock handler JS)
var result = karate.call('helpers.feature');
// after: run the call inside a scenario, or inline the logic
var result = { /* computed directly in JS */ }; Defensive patterns
Strategy: type-guard
Validate before calling
// only call features from scenario-executing JS; do not call from mock handler JS
if (typeof karate.call !== 'function') throw new Error('karate.call unavailable'); Type guard
function canCallFeatures() {
try { karate.call; return true; } catch (e) { return false; }
}
// and structurally: only invoke karate.call inside Scenario/Background JS, never in mock server scripts Try / catch
var result;
try {
result = karate.call('classpath:x.feature');
} catch (e) {
if (String(e.message).includes('not available in this context')) {
throw new Error('karate.call must run inside a Scenario, not a mock/standalone JS context');
}
throw e;
} Prevention
- Restrict karate.call usage to Scenario/Background JS where a ScenarioRuntime exists.
- In mock server handlers, implement logic inline in JS rather than calling other features.
- Document in shared JS helpers which karate APIs they rely on and where they may execute.
When it happens
Trigger: Invoking karate.call('other.feature') (with any arguments, even none) from a JS context where the karate bridge has no ScenarioRuntime — e.g. inside a mock server handler or a standalone JS engine.
Common situations: Mock contexts responding to requests by trying to call another feature; utility JS evaluated outside scenario execution; hooks that run before/after a runtime exists.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- karate.match(String) is not available in this context
- karate.setupOnce() is not available in this context
- karate.callonce() is not available in this context
- karate.callSingle() is not available in this context
- Uint8Array is fixed-size
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/e825c2b57f3fbe0e.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJs.java:690
ScenarioRuntime rt = ScenarioRuntime.currentOrNull();
if (rt == null) {
rt = getRuntime();
}
if (rt == null) {
throw new RuntimeException("karate.match(String) is not available in this context");
}
String expression = args[0].toString();
Result result = rt.getExecutor().evalMatchString(expression, null);
return result.toMap();
}
};
}
private JavaInvokable call() {
return args -> {
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();View on GitHub (pinned to a22eb90246)