{"record":{"id":"afb3c2df33db755d","repo":"karatelabs/karate","slug":"cannot-set-name","errorCode":null,"errorMessage":"cannot set '${name}'","messagePattern":"cannot set '(.+?)'","errorType":"exception","errorClass":"JsErrorException (typeError)","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java","lineNumber":1210,"sourceCode":"            objectLike.putMember(name, value, context, context.strict);\n            firePropertySet(context, name, value, oldValue, object, trackingNode);\n        } else if (object instanceof Map) {\n            Map<String, Object> map = (Map<String, Object>) object;\n            Object oldValue = map.get(name);\n            map.put(name, value);\n            firePropertySet(context, name, value, oldValue, object, trackingNode);\n        } else if (context.root.bridge != null) {\n            try {\n                if (object instanceof ExternalAccess ja) {\n                    ja.setProperty(name, value);\n                } else {\n                    ExternalAccess ja = context.root.bridge.forInstance(object);\n                    ja.setProperty(name, value);\n                }\n                firePropertySet(context, name, value, null, object, trackingNode);\n            } catch (Exception e) {\n                logger.error(\"external bridge error: {}\", e.getMessage());\n                throw JsErrorException.typeError(\"cannot set '\" + name + \"'\");\n            }\n        } else {\n            throw JsErrorException.typeError(\"cannot set '\" + name + \"'\");\n        }\n    }\n\n    private static void firePropertySet(CoreContext context, String name, Object value, Object oldValue, Object target, Node node) {\n        if (context.root.listener != null) {\n            context.root.listener.onBind(BindEvent.propertySet(name, value, oldValue, target, context, node));\n        }\n    }\n\n    private static Object postIncDecByIndex(Object object, Object index, boolean isIncrement, CoreContext context) {\n        if (index instanceof Number n) {\n            int i = denseIndex(n);\n            if (object instanceof List && i >= 0) {\n                List<Object> list = (List<Object>) object;\n                Object oldValue = i < list.size() ? list.get(i) : Terms.UNDEFINED;","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java#L1192-L1228","documentation":"A TypeError raised when a property write is routed to the external Java bridge (context.root.bridge) and the bridge call throws — Karate logs the underlying bridge error and rethrows as 'cannot set <name>'. The same message is also thrown in the final else branch when the target object type supports no property write at all. Effectively: the engine could not assign this property on this object.","triggerScenarios":"Setting a property on a bridged Java/external object (via the JS<->Java bridge) where setProperty fails (wrong type, read-only field, exception inside the Java setter), or assigning to a value whose type has no setter support (e.g. a primitive or immutable value in a `super`/receiver path).","commonSituations":"Karate UI/API integrations writing to Java objects from JS, typed value mismatches (assigning a string to an int-typed bean property), attempting to mutate a read-only or frozen host object.","solutions":["Check the log line 'external bridge error: ...' for the real underlying exception and fix that root cause (type mismatch, exception in setter).","Verify the property exists and is writable on the target Java object; use a setter-compatible name and type.","Coerce the value to the expected Java type before assigning (e.g. wrap numbers/strings appropriately).","If the object genuinely doesn't support writes, store the value in a JS variable or Map instead of the host object."],"exampleFix":"// before\n* eval javaObj.count = 'abc'  // bridge setter expects int -> throws\n// after\n* eval javaObj.count = 5","handlingStrategy":"try-catch","validationCode":"// Java side: validate writability before the call\nif (bean.getProperty(name) == null && !bean.hasWritableProperty(name)) throw new IllegalStateException(name + \" not writable\");","typeGuard":null,"tryCatchPattern":"* eval\n  try { karate.set('javaObj.field', v) } catch (e) { karate.log('bridge set failed: ' + e) }","preventionTips":["Read the 'external bridge error' log line for the root cause.","Match assigned value types to Java setter signatures.","Only write to properties the bridge exposes as settable.","Keep bridge objects for behavior; store mutable state in JS Maps."],"tags":["javascript","property-write","java-bridge","type-error"],"backgroundTag":"unsupported-operation","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"}