Key 'xxx' returned an object instead of string

320 views
Skip to first unread message

Csongor Varga

unread,
Jan 11, 2018, 2:46:14 PM1/11/18
to Node-RED
Hi Guys,

I have created a debugging function node to print the current msg.topic to the function node status:
node.status({fill:"blue",shape:"ring",text:msg.topic});

The node status reads this:
Key 'node-red:switch (en-US)' returned an object instead of string

Why is that? On the other hand a code like this works just fine:
if (msg.topic==="switch") {
}

Also when is put the topic into debug, it says that it is a string.

I am confused. What am I missing?

Regards,
Csongor




Message has been deleted

Hugobox

unread,
Jan 11, 2018, 4:03:08 PM1/11/18
to Node-RED
Hi!

Seems like a bug with certain reserved words. "function" reacts the same way.

Nick O'Leary

unread,
Jan 11, 2018, 4:09:51 PM1/11/18
to Node-RED Mailing List
> "switch" is a reserved word in javascript:

Close but not quiet the explanation for this.

The Node-RED UI supports multiple languages. Currently we have complete translations in English (obviously), Japanese and Chinese.

That means any piece of text we display in the editor needs to be translatable in the locale of the browser accessing node-red. The node status text is set in the runtime. So that it can support translations, the editor first checks the node message catalog to see if the text passed over status is actually a key into the message catalog. If it is, it displays the translated message - otherwise the original text is displayed.

That's all great, until someone innocently uses some text that is a partial match in the catalog. In this instance, 'switch' is a key in the catalog, but rather than a message key, its value is an object of subkeys - https://github.com/node-red/node-red/blob/915d73e6f22550fe69244958beb264f64115638e/nodes/core/locales/en-US/messages.json#L530

And that's what's causes the error message you see to appear. It should be falling back to your original text in this case... so long story short, this is a bug which needs fixing.

Nick



On 11 January 2018 at 20:55, Hugobox <hug...@gmail.com> wrote:
Hi! "switch" is a reserved word in javascript:


So change it to anything else and it will work.


On Thursday, January 11, 2018 at 2:46:14 PM UTC-5, Csongor Varga wrote:

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/c5bf335f-3f49-46cb-97bb-3c5899039448%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Csongor Varga

unread,
Jan 11, 2018, 4:18:27 PM1/11/18
to Node-RED
Absolutely wow :). Thanks for this. I was looking at that single line for hours trying to figure out what I have done wrong.

So I updated my code and it works:
node.status({fill:"blue",shape:"ring",text:"Value: "+msg.topic});
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages