{"record":{"id":"05b47a4e892fd633","repo":"karatelabs/karate","slug":"cannot-assign-to-read-only-property-name","errorCode":null,"errorMessage":"Cannot assign to read only property '${name}'","messagePattern":"Cannot assign to read only property '(.+?)'","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/DataSlot.java","lineNumber":57,"sourceCode":"        super(name);\n        this.value = value;\n    }\n\n    @Override\n    boolean isAccessor() {\n        return false;\n    }\n\n    @Override\n    Object read(Object receiver, CoreContext ctx) {\n        return value;\n    }\n\n    @Override\n    void write(Object receiver, Object newValue, CoreContext ctx, boolean strict) {\n        if (!isWritable()) {\n            if (strict) {\n                throw JsErrorException.typeError(\n                        \"Cannot assign to read only property '\" + name + \"'\");\n            }\n            return;\n        }\n        this.value = newValue;\n    }\n\n    @Override\n    public String toString() {\n        return name + \"=\" + value;\n    }\n\n}\n","sourceCodeStart":39,"sourceCodeEnd":71,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/DataSlot.java#L39-L71","documentation":"Thrown when script code writes to a read-only data slot (a property/binding backed by DataSlot whose writable flag is false) while the engine is in strict mode. In non-strict mode the write is silently ignored, matching ECMAScript sloppy-mode behavior. This guards immutable bindings exposed by the host (e.g. built-ins or karate-provided variables that must not be overwritten).","triggerScenarios":"Assigning to a host-provided read-only variable/property such as a karate built-in (`karate = ...`) or a frozen/exposed constant binding, from strict-mode script code; also via any property-write path that resolves to a DataSlot with isWritable() == false.","commonSituations":"Trying to override karate's built-in `karate` object or engine-provided globals in a feature/script; attempting to redefine library-exposed constants; strict-mode modules copied from browser code that assumed writable globals.","solutions":["Stop assigning to the built-in — choose a different variable name for your own value","If it is your own exposed binding, mark it writable when creating the DataSlot","Remove the assignment; if you need a modified copy, clone into a new variable","Check whether the script is unintentionally strict (module/type=module contexts) if the write was meant to be silently ignored"],"exampleFix":"// before\nkarate = { myHelper: true }; // read-only built-in\n// after\nvar myKarateExt = { myHelper: true };","handlingStrategy":"type-guard","validationCode":"// never assign to engine-provided built-ins; pick your own names\nvar myData = { foo: 1 }; // instead of karate = {...}","typeGuard":"function isWritableTarget(t) { return t !== karate && !isBuiltInName(t); }","tryCatchPattern":null,"preventionTips":["Treat built-ins (karate, etc.) as read-only namespaces","Use distinct names for your own helpers","Avoid strict-mode reliance on silent sloppy-mode writes","If exposing bindings from host code, set writable deliberately"],"tags":["javascript","read-only","strict-mode","property-assignment"],"backgroundTag":"permission-denied","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"}