Uncaught TypeError in util.setObjectProperty on Array Paths
Author: codeCraft-RitikCreated Sep 8, 2026Updated Sep 8, 2026
Labelsneeds-triage
Current Behavior
When using RED.util.setObjectProperty (or RED.util.setMessageProperty) to traverse or delete a nested property on a path containing an array with null or primitive elements (e.g. payload.arr[0].subprop.deep where arr = [null] or arr = ["text"]), the runtime throws an unhandled:
TypeError: Cannot convert undefined or null to object
at Object.hasOwn (<anonymous>)
at Object.setObjectProperty (@node-red/util/lib/util.js:475:24)Because this error occurs synchronously during message property manipulation (such as inside a Change node or custom function node), it bypasses normal flow error handling and crashes the entire Node-RED Node.js process.
Expected Behavior
setObjectProperty should gracefully detect that the array element is not an object/function and return false, consistent with how object properties are already guarded at line 476 of @node-red/util/lib/util.js.
Steps To Reproduce
- Call
util.setObjectPropertyon an object containing an array with anullor primitive value:const util = require('@node-red/util').util; // Reproduce deep property set crash on null array element: const msg1 = { arr: [null] }; util.setObjectProperty(msg1, 'arr[0].subprop.leaf', 123); // Result: Uncaught TypeError: Cannot convert undefined or null to object // Reproduce deep property set crash on primitive array element: const msg2 = { arr: [123] }; util.setObjectProperty(msg2, 'arr[0].subprop.leaf.deep', 456); // Result: Uncaught TypeError: Cannot convert undefined or null to object // Reproduce property deletion crash on null array element: const msg3 = { arr: [null] }; util.setObjectProperty(msg3, 'arr[0].subprop'); // Result: Uncaught TypeError: Cannot convert undefined or null to object - Observe that Node-RED throws an uncaught
TypeErrorand terminates the process instead of returningfalse.
Example flow
[
{
"id": "tab_setobjectproperty_repro",
"type": "tab",
"label": "Repro: setObjectProperty Crash",
"disabled": false,
"info": ""
},
{
"id": "inject_null_array",
"type": "inject",
"z": "tab_setobjectproperty_repro",
"name": "Send Array with Null",
"props": [
{
"p": "payload",
"v": "{\"arr\":[null]}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 190,
"y": 140,
"wires": [
[
"change_deep_prop"
]
]
},
{
"id": "change_deep_prop",
"type": "change",
"z": "tab_setobjectproperty_repro",
"name": "Set deep prop: payload.arr[0].subprop.leaf",
"rules": [
{
"t": "set",
"p": "payload.arr[0].subprop.leaf",
"pt": "msg",
"to": "test-value",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 490,
"y": 140,
"wires": [
[
"debug_output"
]
]
},
{
"id": "debug_output",
"type": "debug",
"z": "tab_setobjectproperty_repro",
"name": "output",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 760,
"y": 140,
"wires": []
}
]Environment
- Node-RED version: 5.0.6 (and all prior versions)
- Node.js version: v18.x / v20.x / v22.x / v24.x
- npm version: 10.x / 11.x
- Platform/OS: Windows / Linux / macOS
- Browser: N/A (Core runtime engine)
Source: node-red/node-red