# Need help with the error part please! Cannot display error

**URL:** <https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830>\
**Category:** General\
**Created:** [1 December 2020 20:28 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830 "2020-12-01T20:28:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKA](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SKA](https://discourse.nodered.org/u/SKA)\
**Post date:** [1 December 2020 20:28 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/1 "2020-12-01T20:28:01Z")

</div>

I am trying to display an error if the value is less than or equal to zero, but it for some reasons isn't working. I have tried searching, but no luck. I know it is probably something very small that needs to be fixed though I am not able to figure it out. I have been struggling on this for 2 days now. Any help will be appreciated. I am not sure if there is a way to add a node or display it within the code.  
I prefer if I can add a separate node to display error. I have attached my flow below. If someone can please help me with the solution for this.

```auto
[{"id":"cb816b24.fe39e8","type":"inject","z":"350d0535.68069a","name":"LuxReading","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:340","payloadType":"str","x":210,"y":360,"wires":[["a47c5a17.2edfb8"]]},{"id":"aea09e2c.4c494","type":"split","z":"350d0535.68069a","name":"","splt":":","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":360,"wires":[["7fcd5036.5961b"]]},{"id":"7fcd5036.5961b","type":"switch","z":"350d0535.68069a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":360,"wires":[["29a1d2c9.5eefee"]]},{"id":"29a1d2c9.5eefee","type":"function","z":"350d0535.68069a","name":"Comparison ","func":"msg.payload = Number (msg.payload);\nmsg.Lux; // new stored value\nvar actualLux = 400;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0) // if less than or equal to zero then it should\n // disaply error\n{\n msg.Lux = \"Something is wrong\";\n return msg;\n}\nelse if (msg.payload == actualLux) // keeps it same if matches\n{\n return msg;\n}\nelse if(msg.payload > actualLux) // adjust the value accordingly\n{\n correction = msg.payload - actualLux;\n msg.Lux = msg.payload - correction;\n return msg;\n}\nelse if(msg.payload < actualLux) // adjust the value accordingly\n{\n correction = actualLux - msg.payload;\n msg.Lux = msg.payload + correction;\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":850,"y":360,"wires":[["a4c764cf.6e1a38"]]},{"id":"a4c764cf.6e1a38","type":"debug","z":"350d0535.68069a","name":"Lux_Value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":360,"wires":[]},{"id":"a47c5a17.2edfb8","type":"switch","z":"350d0535.68069a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Lux","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":360,"wires":[["aea09e2c.4c494"]]}]

```

Thank you!!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [1 December 2020 20:52 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/2 "2020-12-01T20:52:46Z")

</div>

Looking at the switch node.

Which message will be passed ? One that has a value larger than 0.  
So the function node will never see a payload \<1

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 December 2020 21:06 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/3 "2020-12-01T21:06:23Z")

</div>

I dont understand the split node either.  
Maybe something like this.

```auto
[{"id":"2f34c5ac.444dca","type":"inject","z":"8d22ae29.7df6d","name":"LuxReading","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:340","payloadType":"str","x":160,"y":3201,"wires":[["e4e62746.44a79"]]},{"id":"e4e62746.44a79","type":"switch","z":"8d22ae29.7df6d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Lux","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":3200,"wires":[["d20169ec.017868"]]},{"id":"d20169ec.017868","type":"function","z":"8d22ae29.7df6d","name":"Comparison ","func":"msg.payload = Number (msg.payload.split(\":\")[1]);\nmsg.Lux = 0; // new stored value\nvar actualLux = 400;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0 || isNaN(msg.payload)) // if less than or equal to zero then it should\n // disaply error\n{\n node.warn(\"Something is wrong\");\n return;\n}\nelse if (msg.payload == actualLux) // keeps it same if matches\n{\n return msg;\n}\nelse if(msg.payload > actualLux) // adjust the value accordingly\n{\n correction = msg.payload - actualLux;\n msg.Lux = msg.payload - correction;\n return msg;\n}\nelse if(msg.payload < actualLux) // adjust the value accordingly\n{\n correction = actualLux - msg.payload ;\n msg.Lux = msg.payload + correction;\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":3200,"wires":[["cfc5e4c3.db4838"]]},{"id":"f7e9ea6c.f6b3d","type":"inject","z":"8d22ae29.7df6d","name":"lux 440","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:440","payloadType":"str","x":120,"y":3260,"wires":[["e4e62746.44a79"]]},{"id":"4036ee2e.6b1b","type":"inject","z":"8d22ae29.7df6d","name":"Lux junk","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:dd","payloadType":"str","x":140,"y":3300,"wires":[["e4e62746.44a79"]]},{"id":"d47fc6e8.d057d8","type":"inject","z":"8d22ae29.7df6d","name":"Lux < 0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:-1","payloadType":"str","x":140,"y":3340,"wires":[["e4e62746.44a79"]]},{"id":"cfc5e4c3.db4838","type":"debug","z":"8d22ae29.7df6d","name":"Lux_Value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":3200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![SKA](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SKA](https://discourse.nodered.org/u/SKA)\
**Post date:** [1 December 2020 23:39 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/4 "2020-12-01T23:39:30Z")

</div>

Thank you so much for your response. I have a question: Is there a way I can do a pop message and how would that work. Also, is it possible to do within the code?

---

<div class="post-metadata">

**Author:** ![SKA](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SKA](https://discourse.nodered.org/u/SKA)\
**Post date:** [1 December 2020 23:40 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/5 "2020-12-01T23:40:12Z")

</div>

Oh so I can pass multiple inside the switch node?

---

<div class="post-metadata">

**Author:** ![SKA](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SKA](https://discourse.nodered.org/u/SKA)\
**Post date:** [1 December 2020 23:45 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/6 "2020-12-01T23:45:34Z")

</div>

split node I used to catch the colon sign so it splits the Lux and the value using colon. Also do I have to inject the less than zero in a separate node for it to show error message?

---

<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:** [30 January 2021 23:45 UTC](https://discourse.nodered.org/t/need-help-with-the-error-part-please-cannot-display-error/36830/7 "2021-01-30T23:45:49Z")

</div>

Closed on 30 January 2021 23:45 UTC

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