{"record":{"id":"d996dcbde4d1a912","repo":"karatelabs/karate","slug":"karate-call-with-sharedscope-requires-a-feature-path","errorCode":null,"errorMessage":"karate.call() with sharedScope requires a feature path","messagePattern":"karate\\.call\\(\\) with sharedScope requires a feature path","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":706,"sourceCode":"            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();\n                arg = args.length > 2 ? args[2] : null;\n            } else {\n                path = args[0].toString();\n                arg = args.length > 1 ? args[1] : null;\n            }\n            Object result = rt.executeJsCall(path, arg);\n            if (sharedScope && result instanceof Map) {\n                // Merge result variables into current scope (only meaningful for single-call results)\n                @SuppressWarnings(\"unchecked\")\n                Map<String, Object> resultMap = (Map<String, Object>) result;\n                for (var entry : resultMap.entrySet()) {\n                    engine.put(entry.getKey(), entry.getValue());\n                }\n            }\n            return result;\n        };","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L688-L724","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nkarate.call(true);\n// after\nkarate.call(true, 'classpath:helpers/shared.feature', { token: token });","handlingStrategy":"validation","validationCode":"if (typeof sharedScope === 'boolean' && (typeof path !== 'string' || path.length === 0)) {\n  throw new Error('karate.call(sharedScope, path) needs a feature path');\n}\nkarate.call(sharedScope, path, arg);","typeGuard":"function argsValidForCall(args) {\n  if (typeof args[0] === 'boolean') return args.length >= 2 && typeof args[1] === 'string' && args[1].length > 0;\n  return typeof args[0] === 'string' && args[0].length > 0;\n}","tryCatchPattern":"var result;\ntry {\n  result = karate.call(sharedScope, path, arg);\n} catch (e) {\n  if (String(e.message).includes('with sharedScope requires a feature path')) {\n    throw new Error('path argument missing; signature is karate.call(sharedScope, path[, arg])');\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["javascript","api-misuse","missing-argument","argument-order"],"backgroundTag":"missing-required-argument","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"}