{"record":{"id":"f0d73f553fd7f17e","repo":"karatelabs/karate","slug":"call-with-tag-selector-requires-a-feature-context","errorCode":null,"errorMessage":"call with tag selector requires a feature context","messagePattern":"call with tag selector requires a feature context","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/StepExecutor.java","lineNumber":440,"sourceCode":"            } else if (evaluated instanceof FeatureCall || evaluated instanceof Feature) {\n                executeFeatureCall(evaluated, parts.arg(), resultVar);\n                return;\n            }\n        }\n\n        // Standard feature call\n        CallExpression call = parseCallExpression(callExpr);\n        call.resultVar = resultVar;\n\n        // Resolve the feature file relative to current feature\n        FeatureRuntime fr = runtime.getFeatureRuntime();\n        Feature calledFeature;\n\n        if (call.sameFile) {\n            // Same-file tag call - use current feature\n            calledFeature = fr != null ? fr.getFeature() : null;\n            if (calledFeature == null) {\n                throw new RuntimeException(\"call with tag selector requires a feature context\");\n            }\n        } else {\n            Resource calledResource = fr != null\n                    ? fr.resolve(call.path)\n                    : Resource.path(call.path);\n            calledFeature = Feature.read(calledResource);\n        }\n\n        // Check if it's an array loop call\n        if (call.argList != null) {\n            runtime.setVariable(resultVar, callFeatureLoop(calledFeature, call.argList, call.tagSelector, call.lineFilters));\n            return;\n        }\n\n        // Single call\n        Map<String, Object> resultVars = callFeatureSingle(calledFeature, call.arg, call.tagSelector, call.lineFilters);\n        if (resultVars != null) {\n            runtime.setVariable(resultVar, resultVars);","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/StepExecutor.java#L422-L458","documentation":"A 'call' step using a tag selector (e.g. 'call read(\"@tagName\")') resolves against the current feature; when the step executor has no enclosing FeatureRuntime/Feature in context, Karate throws this RuntimeException because tag-based same-file calls have nothing to search.","triggerScenarios":"Invoking evalCallExpression / executeCallWithResult with call.sameFile=true (a '@tag' selector) while fr is null or fr.getFeature() is null — e.g. calling a tag-scoped section from outside a loaded feature, or embedding the step executor in a non-feature harness.","commonSituations":"Programmatic/driver use of Karate's step engine without a FeatureRuntime; running a snippet harness that calls tag sections; tests invoking karate.call() with a '@tag' path before any feature is loaded.","solutions":["Ensure the call is executed within a loaded feature (a proper FeatureRuntime / runner context)","Replace the '@tag' selector with an explicit path to the feature or Scenario: 'call read(\"path/to/feature.feature\")'","If calling code directly, construct a Feature for the current resource so getFeature() is non-null"],"exampleFix":"// before: tag selector with no feature context\ncall read('@setup-data')\n// after: call the feature explicitly or ensure runner context\ncall read('classpath:helpers/setup.feature')","handlingStrategy":"try-catch","validationCode":"// guard before tag-selector calls: need a feature context\nif (callExpr.startsWith(\"@\") && featureRuntime == null) {\n    throw new IllegalStateException(\"@tag call requires a loaded feature context\");\n}","typeGuard":null,"tryCatchPattern":"try { result = karate.call(expr, arg); } catch (RuntimeException e) { if (e.getMessage().contains(\"requires a feature context\")) { throw new IllegalStateException(\"use explicit feature path instead of @tag selector\"); } throw e; }","preventionTips":["Use @tag selectors only inside features run by the Karate runner","Prefer explicit feature paths in programmatic calls","Initialize FeatureRuntime before invoking the step engine directly"],"tags":["karate","call","feature","tags"],"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"}