{"record":{"id":"e825c2b57f3fbe0e","repo":"karatelabs/karate","slug":"karate-call-is-not-available-in-this-context","errorCode":null,"errorMessage":"karate.call() is not available in this context","messagePattern":"karate\\.call\\(\\) is not available in this context","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":690,"sourceCode":"                ScenarioRuntime rt = ScenarioRuntime.currentOrNull();\n                if (rt == null) {\n                    rt = getRuntime();\n                }\n                if (rt == null) {\n                    throw new RuntimeException(\"karate.match(String) is not available in this context\");\n                }\n                String expression = args[0].toString();\n                Result result = rt.getExecutor().evalMatchString(expression, null);\n                return result.toMap();\n            }\n        };\n    }\n\n    private JavaInvokable call() {\n        return args -> {\n            ScenarioRuntime rt = getRuntime();\n            if (rt == null) {\n                throw new RuntimeException(\"karate.call() is not available in this context\");\n            }\n            if (args.length == 0) {\n                throw new RuntimeException(\"karate.call() requires at least one argument (feature path)\");\n            }\n            // V1 compatible signatures:\n            // call(path) - isolated scope\n            // call(path, arg) - isolated scope with arg\n            // call(sharedScope, path) - explicit scope\n            // call(sharedScope, path, arg) - explicit scope with arg\n            boolean sharedScope = false;\n            String path;\n            Object arg;\n            if (args[0] instanceof Boolean) {\n                sharedScope = (Boolean) args[0];\n                if (args.length < 2) {\n                    throw new RuntimeException(\"karate.call() with sharedScope requires a feature path\");\n                }\n                path = args[1].toString();","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L672-L708","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (in mock handler JS)\nvar result = karate.call('helpers.feature');\n// after: run the call inside a scenario, or inline the logic\nvar result = { /* computed directly in JS */ };","handlingStrategy":"type-guard","validationCode":"// only call features from scenario-executing JS; do not call from mock handler JS\nif (typeof karate.call !== 'function') throw new Error('karate.call unavailable');","typeGuard":"function canCallFeatures() {\n  try { karate.call; return true; } catch (e) { return false; }\n}\n// and structurally: only invoke karate.call inside Scenario/Background JS, never in mock server scripts","tryCatchPattern":"var result;\ntry {\n  result = karate.call('classpath:x.feature');\n} catch (e) {\n  if (String(e.message).includes('not available in this context')) {\n    throw new Error('karate.call must run inside a Scenario, not a mock/standalone JS context');\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["javascript","runtime-context","call","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}