{"record":{"id":"cb529f13b660f895","repo":"karatelabs/karate","slug":"same-file-tag-call-requires-a-feature-context","errorCode":null,"errorMessage":"same-file tag call requires a feature context","messagePattern":"same-file tag call requires a feature context","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/StepExecutor.java","lineNumber":2762,"sourceCode":"\n    /**\n     * Execute a feature call with a Feature or FeatureCall object.\n     * Used when the call expression evaluates to a Feature variable.\n     * Supports array loop calling when argExpr evaluates to a List.\n     */\n    @SuppressWarnings(\"unchecked\")\n    private void executeFeatureCall(Object featureObj, String argExpr, String resultVar) {\n        FeatureRuntime fr = runtime.getFeatureRuntime();\n\n        Feature calledFeature;\n        String tagSelector = null;\n\n        if (featureObj instanceof FeatureCall) {\n            FeatureCall fc = (FeatureCall) featureObj;\n            if (fc.isSameFile()) {\n                calledFeature = fr != null ? fr.getFeature() : null;\n                if (calledFeature == null) {\n                    throw new RuntimeException(\"same-file tag call requires a feature context\");\n                }\n            } else {\n                calledFeature = fc.getFeature();\n            }\n            tagSelector = fc.getTagSelector();\n        } else if (featureObj instanceof Feature) {\n            calledFeature = (Feature) featureObj;\n        } else {\n            throw new RuntimeException(\"expected Feature or FeatureCall, got: \" + featureObj.getClass());\n        }\n\n        // Karate-expression eval handles inline JSON with embedded `#(...)`,\n        // arrays, variables, and bare JS uniformly.\n        Object argObj = argExpr == null ? null : evalKarateExpression(argExpr);\n\n        // Check if it's an array loop call\n        if (argObj instanceof List) {\n            List<Map<String, Object>> results = callFeatureLoop(calledFeature, (List<?>) argObj, tagSelector, null);","sourceCodeStart":2744,"sourceCodeEnd":2780,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/StepExecutor.java#L2744-L2780","documentation":"Identical in intent to the previous error but raised on the FeatureCall code path: when a `call` argument is a FeatureCall marked same-file with a tag selector, the executor derives the feature from the current feature runtime; if none exists (fr is null or has no Feature) it throws. A same-file tag call fundamentally requires a live feature to filter scenarios from.","triggerScenarios":"A call step whose argument evaluates to a same-file FeatureCall (created with a tag selector) executed in a context with no current Feature; e.g. dynamic `call foo` where foo was built programmatically as a same-file call and run outside a feature.","commonSituations":"Constructing FeatureCall objects in JS/Java and invoking them from embedded scripts; runner setups that execute steps without an owning feature; refactors that moved a same-file tag call into a shared utility executed standalone.","solutions":["Execute the call within a feature runtime that has an active Feature","Replace the same-file tag call with an explicit path call: call classpath:path/to/file.feature@tag","Avoid caching/reusing FeatureCall objects across contexts","Verify the feature runtime (fr) is set before dynamic calls"],"exampleFix":"// before\n* def fc = karate.readAndCall('@smoke')  // same-file, no feature ctx\n// after\n* call classpath:examples/users.feature@smoke","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { karate.call(fc) } catch (e) { if (String(e).indexOf('feature context') >= 0) karate.call('explicit.feature@tag') }","preventionTips":["Construct FeatureCall objects only where a feature runtime exists","Use path-based calls for dynamic invocation","Test dynamic call helpers inside a real feature run"],"tags":["call","feature","tags","state"],"backgroundTag":"invalid-state-transition","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"}