{"record":{"id":"41775a149e2cc113","repo":"karatelabs/karate","slug":"name-is-not-defined","errorCode":null,"errorMessage":"${name} is not defined","messagePattern":"(.+?) is not defined","errorType":"exception","errorClass":"JsErrorException (referenceError)","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java","lineNumber":657,"sourceCode":"                        throw SlotTable.tdzError(node.getText());\n                    }\n                    if (functionCall && context.root.bridge != null && v instanceof ExternalAccess ea) {\n                        return externalConstructor(ea);\n                    }\n                    return v;\n                }\n            }\n        }\n        return getRefExprByName(node, context, functionCall);\n    }\n\n    // Name-keyed tail of getRefExpr, outlined to keep the slot fast path small\n    // enough to inline reliably.\n    private static Object getRefExprByName(Node node, CoreContext context, boolean functionCall) {\n        String name = node.getText();\n        Object result = context.getOrNotFound(name);\n        if (result == CoreContext.NOT_FOUND) {\n            throw JsErrorException.referenceError(name + \" is not defined\");\n        }\n        if (functionCall && context.root.bridge != null && result instanceof ExternalAccess ea) {\n            return externalConstructor(ea);\n        }\n        return result;\n    }\n\n    private static JsConstructor externalConstructor(ExternalAccess ea) {\n        return (c, args) -> ea.construct(args);\n    }\n\n    /**\n     * Shared {@code REF_DOT_EXPR} resolution for both the value-only\n     * ({@link #getRefDotExpr}) and call-site ({@link #getCallableRefDotExpr})\n     * paths. Captures every AST shape (named dot, optional dot, optional\n     * bracket, optional call), the external-bridge fallback on eval failure,\n     * and the {@code ?.} short-circuit propagation in one place.\n     * <p>","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java#L639-L675","documentation":"This is Karate's embedded JS engine's ReferenceError, thrown when a bare identifier is looked up in the JS scope (getRefExprByName) and the context resolves it to CoreContext.NOT_FOUND. Karate throws it because evaluating an unknown name would otherwise silently yield null, hiding typos and missing variables. Unlike undefined property reads, an undefined standalone name is treated as a hard reference error, matching JavaScript semantics.","triggerScenarios":"Evaluating a Karate JS expression that references a bare variable name that was never defined: a typo in a variable name (e.g. `reponse` instead of `response`), using a variable in a `match`/`assert`/`eval` before it is `def`'ed, or referencing a Scenario-Outline column that doesn't exist for the current row.","commonSituations":"Typos in feature files, variables defined in a Scenario but referenced in Background (or vice versa), forgetting `def` before use in `karate.call` arguments, renaming a variable without updating all match/assert expressions, calling a shared scope variable from a called feature that wasn't passed in.","solutions":["Check spelling of the identifier in the JS expression against the `def` statements and Scenario-Outline Examples column names.","Add a `def` for the variable (or `* def name = karate.get('name', defaultValue)`) before the expression that uses it.","If the variable comes from a called feature, ensure it is returned/assigned (e.g. `* def result = call read('x.feature')`) and reference `result.field`, not the raw name.","Use `karate.get('name')` (which returns null) instead of a bare reference when absence is expected."],"exampleFix":"// before (typo, variable never defined)\n* match reponse.status == 200\n// after\n* def response = call read('helper.feature')\n* match response.status == 200","handlingStrategy":"validation","validationCode":"// Karate: check before use\n* assert karate.get('myVar') != null || karate.fail('myVar is not defined')","typeGuard":null,"tryCatchPattern":"// JS eval\ntry { doThing(myVar) } catch (e) { karate.log('reference error: ' + e); myVar = karate.get('myVar', defaultVal); }","preventionTips":["Keep variable names consistent; copy-paste `def` names rather than retyping them.","Use karate.get('name', default) when a variable may legitimately be absent.","Run Scenario-Outline expressions against all Examples rows in review.","Grep features for identifiers before renaming a def."],"tags":["javascript","reference-error","undefined-variable","karate"],"backgroundTag":"resource-not-found","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"}