{"record":{"id":"2c6f3cb8bae3d0c1","repo":"karatelabs/karate","slug":"property-key-is-null","errorCode":null,"errorMessage":"property key is null","messagePattern":"property key is null","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsObjectConstructor.java","lineNumber":553,"sourceCode":"        return new JsObject(desc);\n    }\n\n    /** Returns the own {@link AccessorSlot} at {@code key} when one exists,\n     *  {@code null} otherwise (own data property, missing, or unsupported\n     *  type). Scoped to own properties only — for the chain-walking variant\n     *  see {@code PropertyAccess#findAccessorInChain}. */\n    private static AccessorSlot ownAccessorSlot(Object obj, String key) {\n        PropertySlot s = PropertyAccess.ownSlot(obj, key);\n        return s instanceof AccessorSlot acc ? acc : null;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    Object defineProperty(Context context, Object[] args) {\n        if (args.length < 1 || !(args[0] instanceof ObjectLike || args[0] instanceof Map)) {\n            throw JsErrorException.typeError(\"Object.defineProperty called on non-object\");\n        }\n        if (args.length < 2) {\n            throw JsErrorException.typeError(\"property key is null\");\n        }\n        if (args.length < 3 || args[2] == null || args[2] == Terms.UNDEFINED) {\n            throw JsErrorException.typeError(\"Property descriptor must be an object\");\n        }\n        // Spec ToPropertyKey: pass ctx so ObjectLike keys dispatch through\n        // ToPrimitive(string) → ToString (test262 Object/defineProperty/\n        // 15.2.3.6-2-{20,24,25,39,41,43,44,45,46,47,48} pass arrays / boxed\n        // booleans / objects with overridden toString as the key arg).\n        CoreContext keyCtx = context instanceof CoreContext c ? c : null;\n        String prop = Terms.toPropertyKey(args[1], keyCtx);\n        Object desc = args[2];\n        ObjectLike descObj;\n        Map<String, Object> descMap;\n        if (desc instanceof ObjectLike ol) {\n            descObj = ol;\n            descMap = ol.toMap();\n        } else if (desc instanceof Map) {\n            descObj = null;","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsObjectConstructor.java#L535-L571","documentation":"Object.defineProperty requires exactly three arguments: target, property key, and descriptor. When called with only a target (no property key argument), the engine throws this TypeError indicating the key argument is missing. The message is somewhat literal — it means no key argument was supplied at all.","triggerScenarios":"Object.defineProperty(obj) or Object.defineProperty(obj, undefined-as-only-second-arg omitted) — i.e. args.length < 2. Passing explicitly undefined as the key is converted by ToPropertyKey and does NOT hit this path; only a missing second argument does.","commonSituations":"Partial application or a wrapper function that drops the key argument; spreading an array shorter than expected: defineProperty(obj, ...[desc]); typos calling a local defineProperty helper with wrong arity.","solutions":["Supply the property key as the second argument","Check the call site / wrapper for dropped arguments when using spread or apply","If the key may be absent, guard: if (key == null) handle before calling"],"exampleFix":"// before\nObject.defineProperty(obj); // key missing\n// after\nObject.defineProperty(obj, 'x', {value: 1});","handlingStrategy":"validation","validationCode":"if (key === undefined) throw new TypeError('property key required before defineProperty');","typeGuard":"function hasKeyArg(key) { return key !== undefined; }","tryCatchPattern":"try { Object.defineProperty(obj, key, desc); }\ncatch (e) { if (String(e).includes('property key is null')) { /* fix call arity — key argument was missing */ } else { throw e; } }","preventionTips":["Always pass all three arguments to Object.defineProperty","Be careful with spread/apply wrappers that can drop arguments","Validate wrapper-function arity in unit tests"],"tags":["javascript","object","missing-argument"],"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"}