JavaScript maybe a flaw in runtime error checking?

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:

context.set('', "schoolName");
context.set('', "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.

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

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.

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 ?

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

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.

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