# JavaScript maybe a flaw in runtime error checking?

**URL:** <https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557>\
**Category:** General\
**Tags:** function-node\
**Created:** [1 December 2022 14:16 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557 "2022-12-01T14:16:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [1 December 2022 14:16 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/1 "2022-12-01T14:16:09Z")

</div>

I am very happy to see that the syntax checking in JavaScript, has very much improved over the last year I am using Node-red.

Maybe it is not the right place to report this, if so, I would like to hear where I should place this issue.  
Lately I encountered a problem that I made by mistake. It took me a while to see my mistake,  
The runtime didn't give me any report on that, it just didn't work, as it rightly shouldn't.

Because I made this mistake myself, I just expected a warning of some kind. The mistake looks much like this:

```auto
context.set('obj.school', "schoolName");
context.set('obj.school.location', "Amsterdam");

```

As you can see, I first declared 'school' as a string-attribute, but the next declaration I treated 'school' as an object, with attribute 'location'. Of course this cannot be, but I didn't get any runtime error report. I was expecting it should. The second declaration wasn't executed as it rightly shouldn't.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 December 2022 14:25 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/2 "2022-12-01T14:25:26Z")

</div>

I don't think base javascript reports that as an error so I don't think we can catch that either.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 December 2022 14:30 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/3 "2022-12-01T14:30:03Z")

</div>

It would report it if strict mode was enabled.

I think it would be helpful to flag this type of thing up because it can be super hard to track down otherwise.

Given this would potentially be a breaking change (throwing errors in existing flows that previously 'worked' by silently ignoring it), we may need to consider how to safely introduce it. Such as making it log a warning initially and then in Node-RED 4.0 making it an error... or some variation of that.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 December 2022 14:34 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/4 "2022-12-01T14:34:10Z")

</div>

If this is (mainly) for use in function nodes - would it make sense to have a settings parameter - so that new settings files from 4.0 would set true - and old ones would carry on being (unset) false ?

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [1 December 2022 20:04 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/5 "2022-12-01T20:04:13Z")

</div>

> [@knolleary](#):
>
> It would report it if strict mode was enabled.

Does it work for you? I'm not getting it to work inside a `function` node. Possibly user error.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 December 2022 08:42 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/6 "2022-12-02T08:42:15Z")

</div>

Unfortunately, You cannot simply specify use strict inside of a function node for that type of issue. Nick was actually referring to using it inside of the core code.

The problem is the function node has no idea there is an issue. It sees a function call with two strings & that matches the function signature perfectly. There is no way this can be type checked unfortunately. So the only way to handle this is inside of the global set function.

---

<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:** [31 January 2023 08:42 UTC](https://discourse.nodered.org/t/javascript-maybe-a-flaw-in-runtime-error-checking/71557/7 "2023-01-31T08:42:15Z")

</div>

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