SYSTEM
Raspi 3B+ running recently updated bookworm
NR 4.0.9
nodejs 20.18.3
Problem
I have a case where JSONata in a change node is producing (to an element of an object) a different value to that displayed in a debug node, or displayed for the object when written to a Global context data.
In this case the object is msg.telegram.error and is displayed as a string "AggregateError", but in a JSONata expression which appends msg.telegram.error to a string, it is displayed as an object {"code":"ETIMEDOUT"}. Nothing else shows there is a msg.telegram.error.code in the message, in fact a meessage element can't be a string and a object at the same time.
I did try to copy to msg.telegram.error to msg.errorT in the change node but no difference, unless I ticked DeepCopy, then ErrorT was displayed empty object in debug node.
I isolated the code into my sandpit and got a copy of msg.telegram by saving it to a globalContext variable telegramTest and saw no change in behaviour.
global.telegramTest is (as displayed in Context Data sidepane)
{"isOnline":false,"error":"AggregateError"}
and sandpit flow is
[
{
"id": "aa47566793e591e0",
"type": "ping",
"z": "db3e3c10fd72ce24",
"protocol": "Automatic",
"mode": "triggered",
"name": "ping Telegram",
"host": "api.telegram.org",
"timer": "20",
"inputs": 1,
"x": 430,
"y": 1000,
"wires": [
[
"6a052fd07e1e5a78"
]
]
},
{
"id": "6a052fd07e1e5a78",
"type": "switch",
"z": "db3e3c10fd72ce24",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "false"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 570,
"y": 1000,
"wires": [
[],
[
"d7911cc18da7a6a5",
"75e9c396dc233886",
"dc4bc07536371b15"
]
]
},
{
"id": "d7911cc18da7a6a5",
"type": "change",
"z": "db3e3c10fd72ce24",
"name": "",
"rules": [
{
"t": "set",
"p": "errorT",
"pt": "msg",
"to": "telegram.error",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "\"Telegram Polling down, Internet and Telegram OK. Error: \" & msg.errorT",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 740,
"y": 1000,
"wires": [
[
"dc4bc07536371b15"
]
]
},
{
"id": "dc4bc07536371b15",
"type": "debug",
"z": "db3e3c10fd72ce24",
"name": "debug 17",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 1080,
"wires": []
},
{
"id": "75e9c396dc233886",
"type": "debug",
"z": "db3e3c10fd72ce24",
"name": "debug 18",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "telegram.error",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 1120,
"wires": []
},
{
"id": "81d711184cd97ddc",
"type": "inject",
"z": "db3e3c10fd72ce24",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "telegram",
"v": "telegramTest",
"vt": "global"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 260,
"y": 1000,
"wires": [
[
"aa47566793e591e0"
]
]
}
]
if I change the inject node so msg.telegram is an object (copied from global context data using its copy data button), then the JSONata works as I expected. (new inject node)
[
{
"id": "81d711184cd97ddc",
"type": "inject",
"z": "db3e3c10fd72ce24",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "telegram",
"v": "{\"isOnline\":false,\"error\":\"AggregateError\"}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 260,
"y": 1000,
"wires": [
[
"aa47566793e591e0"
]
]
}
]
So this msg object has hidden data in it, but worse JSONata is using that hidden data whilst displays in the editor like debug node, and Context data display show different. It is like it has a hidden and not hidden value for ".error", one a string the other an object
For information the message comes from the 2nd output of a Telegram Control node from node-red-contrib-telegrambot. I think I know the cause of the error, but I would like it to report the right error in the future? This post is about hidden data, and JSONata behaving differently to NR in general