I've just bumped into a problem and I just can't believe my eyes. One of our systems started to send emails with undefined values where no such values should appear. So I started to investigate the email sending subflow and added a filter condition with a node.warn() to log it and also checked the global context variable in the editor.
Do you mean the contextStorage section is entirely commented out? I find that surprising but maybe it is ok. Are you looking at the file in your .node-red folder.
I guess that isn't the problem anyway, I couldn't think of any other reason it might be undefined.
Is the global var regularly written to? If so is it possible that it is has been written to with undefined but then gets returned to a sensible value before you refresh the view in the editor? It might be worth tracking down all places it is written to and add traps to check that it is not writing undefined.
[Edit] just a check, do you realise the view in the editor only updates when you click the refresh button?
Yepp, the complete section is commented out. I'm 100% sure that I checked the right file in the right folder.
That global variable is only set once when nodered starts up and never again. I double checked it now by searching for:
and the editor gives only that one function which is connected to the inject that triggers only on startup.
Refreshing the global context in the editor does not change anything with regards to that variable.
I also tried reading that variable simply by a manual inject node which I connected to a debug node and the value is correctly read. However, that I could only check on a normal tab not in the subflow's tab -that's why I suspect that it has to do something with being read in a subflow.
There are a couple of others that are undefined as well which are also set only on startup. But I noticed that there's one (which is also set on startup only) and it's not empty. Funnily enough that's the variable that holds the email addresses that's why the email gets sent but with undefined values in it
I don't know why it appears as if there were more node.warns() either. I suspected that's because of the first new line in the string logged but no clue why all other new line chars later are not treated the same way.
Sure. That's a function node I placed before the email node to filter and log the garbage and also to avoid that the email recipients are spammed with nonsense. This (and the related flow of course) run in a subflow.
I had an idea so I created a new subflow, simply added a function node which reads the global variable and connected it to a debug node. When I trigger this subflow from outside with an inject node, the variable is read correctly so it does not seem to be a general issue of reading a global variable in a subflow. I'll investigate it further but nodered seems to be fine. However, if anyone has any idea on how to catch this red handed, it's welcome