Problem with sort-node

Hello guys,

after upgrading to 19.2 I've got error messages from the "sort" node in the log file.

"TypeError: Cannot read property 'hasOwnProperty' of undefined"

Has anyone an idea how I can fix that?

Best Regards

Rico

Hi - that doesn't sound good. To understand what's happening, we'll need some more details from you.

What version did you upgrade from? What version of node.js are you using?
Is there any more detail in the log around this error?
Can you describe a bit more about what you have the sort node doing? What type of messages are you passing it? How is it configured?

Hi,

thank you for the response.

I did the following (yesterday):

Upgrade from 0.18.7 / Node.js version: v8.11.3
via
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

The upgrade process reported no errors.

Node.js version is now v8.11.4

There are no further details in the log, sorry.

Properties of the node:

Sort: msg.payload
Key: timestamp [in the dropdown is "expression" selected)

Other settings: default.

The input message looks like that:

[{"temp":22.2,"hum":56.3,"timestamp":1536141675895,"_id":"5b8fa96b21e9d4046eae507f"},{"temp":22.2,"hum":56.1,"timestamp":1536141075772,"_id":"5b8fa71321e9d4046eae507e"},
.....
]

As you can see: no special things there :wink:

Thank you.

Rico

I think @knolleary meant the log from node-red-log.
It might be useful if you restarted node red, ran node-red-log and then triggered the error if it does not trigger itself. Then copy/paste the log here, starting from the node red start messages.

@knolleary Nick, here is a small demo demonstrating the error with a catch node showing the error. I'd look deeper but I have to take a grandkid to see my Mom and will be gone for a couple hours.

[{"id":"e45ad070.9a8338","type":"inject","z":"23186a27.e02a7e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":80,"wires":[["a6394ffb.efceb"]]},{"id":"a6394ffb.efceb","type":"function","z":"23186a27.e02a7e","name":"","func":"// this is where you define the legend for \n// the datasets\nvar payloadtime = msg.payload;\nvar temp = getRndInteger(0,1000)/10;\nvar humi = getRndInteger(0,1000)/10;\n\n// Now we build msg.payload\nmsg.payload = { \"temp\"   : temp,\n                \"humi\" : humi,\n                \"timestamp\"   : payloadtime\n};\nreturn msg;\n\n// this code gets a random interger\nfunction getRndInteger(min, max) {\n    return Math.floor(Math.random() * (max - min + 1) ) + min;\n}\n","outputs":1,"noerr":0,"x":230,"y":160,"wires":[["22e1fc80.570934"]]},{"id":"542e6b5.24c3e94","type":"debug","z":"23186a27.e02a7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":570,"y":160,"wires":[]},{"id":"22e1fc80.570934","type":"sort","z":"23186a27.e02a7e","name":"","order":"ascending","as_num":true,"target":"payload.timestamp","targetType":"msg","msgKey":"","msgKeyType":"elem","seqKey":"payload","seqKeyType":"msg","x":410,"y":160,"wires":[["542e6b5.24c3e94"]]},{"id":"5f7bd20a.216a14","type":"catch","z":"23186a27.e02a7e","name":"","scope":null,"x":200,"y":300,"wires":[["c7fb1154.88719"]]},{"id":"c7fb1154.88719","type":"debug","z":"23186a27.e02a7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":440,"y":320,"wires":[]}]

Here is the stack from the catch:

TypeError: Cannot read property 'hasOwnProperty' of undefined
    at processMessage (/usr/local/lib/node_modules/node-red/nodes/core/logic/18-sort.js:201:24)
    at SortNode.<anonymous> (/usr/local/lib/node_modules/node-red/nodes/core/logic/18-sort.js:235:13)
    at emitOne (events.js:116:13)
    at SortNode.emit (events.js:211:7)
    at SortNode.Node.receive (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:215:14)
    at FunctionNode.Node.send (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:202:14)
    at sendResults (/usr/local/lib/node_modules/node-red/nodes/core/core/80-function.js:52:18)
    at FunctionNode.<anonymous> (/usr/local/lib/node_modules/node-red/nodes/core/core/80-function.js:225:21)
    at emitOne (events.js:116:13)
    at FunctionNode.emit (events.js:211:7)
    at FunctionNode.Node.receive (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:215:14)
    at InjectNode.Node.send (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:137:22)
    at InjectNode.<anonymous> (/usr/local/lib/node_modules/node-red/nodes/core/core/20-inject.js:78:26)
	at emitOne (events.js:116:13)
	at InjectNode.emit (events.js:211:7)
	at InjectNode.Node.receive (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:215:14)```

@knolleary seems a bug related to introduction of persistent context. I will create fix and test case.

Sorry, I'm quite new in node-red.

Here is the stack:

{"message":"TypeError: Cannot read property 'hasOwnProperty' of undefined","source":{"id":"7ed36095.7a786","type":"sort","count":1},"stack":"TypeError: Cannot read property 'hasOwnProperty' of undefined\n    at processMessage (/usr/lib/node_modules/node-red/nodes/core/logic/18-sort.js:201:24)\n    at SortNode.<anonymous> (/usr/lib/node_modules/node-red/nodes/core/logic/18-sort.js:235:13)\n    at emitOne (events.js:116:13)\n    at SortNode.emit (events.js:211:7)\n    at SortNode.Node.receive (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:215:14)\n    at Mongo2InputNode.Node.send (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:137:22)\n    at /root/.node-red/node_modules/node-red-contrib-mongodb2/mongodb2/mongodb2.js:304:22\n    at handleCallback (/root/.node-red/node_modules/mongodb/lib/utils.js:120:56)\n    at /root/.node-red/node_modules/mongodb/lib/cursor.js:861:16\n    at handleCallback (/root/.node-red/node_modules/mongodb-core/lib/cursor.js:171:5)\n    at setCursorDeadAndNotified (/root/.node-red/node_modules/mongodb-core/lib/cursor.js:505:3)\n    at nextFunction (/root/.node-red/node_modules/mongodb-core/lib/..."}

Well it seems others are onto the problem already, but just for the record (and in case you need to ask about similar things again) that isn't what I asked for. If you read my request again you will see I asked for the output from the command node-red-log. But as I said it doesn't matter now as it seems the problem has been reproduced. Run it for yourself and you will see the sort of things it tells you.

I know that the response was not exactly what you ask for. But I'm still fighting with node-red-log (it's producing no output on my rpi, dont ask my why). So I thought maybe the stack would be helpfull....
Anyway. Problem seems to be solved. You are the best :slight_smile:

That's unusual. How did you install node-red?

Hi,

opened PR on fixing this problem.

See my second posting.
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

I have installed the whole system again and now I get the following output from node-red-log:

5 Sep 15:51:50 - [info] Started flows
5 Sep 15:52:38 - [error] [sort:7ed36095.7a786] TypeError: Cannot read property 'hasOwnProperty' of undefined

I guess thats not really helpful. Anyway. I'm still learning. As soon as I get the next bug I promise to deliver exactly what is needed...

thx

The output from the log when node-red starts is often useful as well as when it fails. The start gives versions of everything and may flag issues that you hadn't noticed. In this case there wasn't anything else useful but it is always worth looking.