# Weakness in switch node

**URL:** <https://discourse.nodered.org/t/weakness-in-switch-node/72154>\
**Category:** General\
**Created:** [13 December 2022 20:20 UTC](https://discourse.nodered.org/t/weakness-in-switch-node/72154 "2022-12-13T20:20:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abruno06](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/abruno06/32/72551_2.png) [@abruno06](https://discourse.nodered.org/u/abruno06)\
**Post date:** [13 December 2022 20:20 UTC](https://discourse.nodered.org/t/weakness-in-switch-node/72154/1 "2022-12-13T20:20:14Z")

</div>

Hello,

While doing test on NR, I have been facing to this issue

```auto
13 Dec 07:35:45 - [error] [switch:c316c1362446b8d3] TypeError: Cannot read properties of null (reading 'hasOwnProperty')
at processMessage ([/home/mxxxxx/node_modules/@node-red/nodes/core/function/10-switch.js:444:39](mailto:/home/m11172/node_modules/@node-red/nodes/core/function/10-switch.js:444:39))
at processMessageQueue ([/home/mxxxxx/node_modules/@node-red/nodes/core/function/10-switch.js:504:13](mailto:/home/m11172/node_modules/@node-red/nodes/core/function/10-switch.js:504:13))
at SwitchNode._inputCallback ([/home/mxxxxx/node_modules/@node-red/nodes/core/function/10-switch.js:513:13](mailto:/home/m11172/node_modules/@node-red/nodes/core/function/10-switch.js:513:13))
at [/home/mxxxxx/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26](mailto:/home/m11172/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26)
at Object.trigger ([/home/mxxxxx/node_modules/@node-red/util/lib/hooks.js:166:13](mailto:/home/m11172/node_modules/@node-red/util/lib/hooks.js:166:13))
at Node._emitInput ([/home/mxxxxx/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11](mailto:/home/m11172/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11))
at Node.emit ([/home/mxxxxx/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25](mailto:/home/m11172/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25))
at Node.receive ([/home/mxxxxx/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10](mailto:/home/m11172/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10))
at Immediate._onImmediate ([/home/mxxxxx/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52](mailto:/home/m11172/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52))
at process.processImmediate (node:internal/timers:471:21)

```

after troubleshooting, this is related to having a msg with msg.parts= null  
I will not said this is really a bug as issue is related to malformed packet.  
after checking in the code,

```auto
  function processMessage(msg, checkParts, done) {
             var hasParts = msg.hasOwnProperty("parts") &&
                             msg.parts.hasOwnProperty("id") &&
                             msg.parts.hasOwnProperty("index");

```

I think it may be interesting to replace by new JS notation

```auto
 var hasParts = !!(msg?.parts?.id &&
                          msg?.parts?.index);

```

which in case of malformed msg, will not break the flow any more

AB

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 February 2023 20:21 UTC](https://discourse.nodered.org/t/weakness-in-switch-node/72154/2 "2023-02-11T20:21:05Z")

</div>

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