Found a Bug on switch node

Hey Guys.
I think I found a bug on switch node when using it to check if a object has a Key.

Description:
Switch node becomes irresponsive after failing to find a key if parent property does not exist. It throws this error "TypeError: Cannot read property 'hasOwnProperty' of undefined" and Next msg(s) are not analysed and previously corrected filtered msgs no longer passes.

The switch node starts working again only after a full Deploy.

I created a small flow to share.

[{"id":"c5d1a536.8c2938","type":"inject","z":"65d06ce2.1c9964","name":"Error","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"summary\":\"Some text\",\"start\":{\"dateTime\":\"2021-03-01T09:30:00-03:00\"},\"end\":{\"dateTime\":\"2021-03-01T11:30:00-03:00\"},\"id\":\"2ujkh1r4886d51n3p49d8pk66c\"},{\"summary\":\"Some other text\",\"start\":{\"dateTime\":\"2021-03-01T09:30:00-03:00\"},\"end\":{\"dateTime\":\"2021-03-01T11:30:00-03:00\"},\"id\":\"2ja2h8v5usvfb0aeagn8hsjtlc\"},{\"summary\":\"No more meeting please\",\"end\":{\"dateTime\":\"2021-03-01T16:00:00-03:00\"},\"id\":\"1kn7r1rtop70d3nn9ddac5t9f1\"}]","payloadType":"json","x":330,"y":260,"wires":[["1e689a44.a03696"]]},{"id":"c5628ea1.a33d8","type":"switch","z":"65d06ce2.1c9964","name":"","property":"payload.start","propertyType":"msg","rules":[{"t":"hask","v":"dateTime","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":680,"y":200,"wires":[["44a9abf5.2277c4"]]},{"id":"c69cb29f.c0ff9","type":"debug","z":"65d06ce2.1c9964","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":200,"wires":[]},{"id":"1e689a44.a03696","type":"split","z":"65d06ce2.1c9964","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":200,"wires":[["c5628ea1.a33d8"]]},{"id":"44a9abf5.2277c4","type":"join","z":"65d06ce2.1c9964","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":840,"y":200,"wires":[["c69cb29f.c0ff9"]]},{"id":"c4b8e425.987c48","type":"inject","z":"65d06ce2.1c9964","name":"No error","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"summary\":\"Some text\",\"start\":{\"dateTime\":\"2021-03-01T09:30:00-03:00\"},\"end\":{\"dateTime\":\"2021-03-01T11:30:00-03:00\"},\"id\":\"2ujkh1r4886d51n3p49d8pk66c\"},{\"summary\":\"Some other text\",\"start\":{\"dateTime\":\"2021-03-01T09:30:00-03:00\"},\"end\":{\"dateTime\":\"2021-03-01T11:30:00-03:00\"},\"id\":\"2ja2h8v5usvfb0aeagn8hsjtlc\"},{\"summary\":\"No more meeting please\",\"start\":{\"dateTime\":\"2021-03-01T14:00:00-03:00\"},\"end\":{\"dateTime\":\"2021-03-01T16:00:00-03:00\"},\"id\":\"1kn7r1rtop70d3nn9ddac5t9f1\"}]","payloadType":"json","x":340,"y":160,"wires":[["1e689a44.a03696"]]},{"id":"b4c7719b.725ef","type":"comment","z":"65d06ce2.1c9964","name":"Last Item of Array does not have \"start\" property","info":"","x":440,"y":300,"wires":[]}]

I can imagine the behavior to be intentional, but for me failing to find parent property should not break the flow

I think you are right, I am seeing the same issue.
I have also tried it with node-red 1.3 beta and it is the same there.

Can I suggest you make a simpler flow just with a couple of inject nodes sending simple objects rather than the array, and the Switch and debug nodes. Then it should be much easier to see what is going on. If you add an Otherwise to the Switch node it seems that it is not completely locking up but is not correctly identifying the switch condition and the messages go to the second output.

1 Like

Thanks for reporting @paulohlp

Have just pushed a fix for 1.3.

3 Likes

That is just typical of the node-red project, the developers don't even give you time to create a neat test case to show the problem and submit a carefully crafted bug report before they leap in and fix it. It removes all the satisfaction of looking back at all those closed issues you have raised.

4 Likes

Jesus. It was so fast.
Everything related to node-red it´s a great experience. Node-red it´s a Joy, the community, Nick and other are just great.

4 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.