# What is wrong with this?

**URL:** <https://discourse.nodered.org/t/what-is-wrong-with-this/70197>\
**Category:** General\
**Created:** [7 November 2022 09:14 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197 "2022-11-07T09:14:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 November 2022 09:14 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/1 "2022-11-07T09:14:44Z")

</div>

IF YOU KNOW - JUST LIKE THE POST -DONT GIVE OUT THE ANSWER 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d42f1571f22c1bd3791a8f3620046e2e52ec345.png)

I was working on real flow late last night and needed to change from outputting on payload to payload.text to feed the mastodon node instead of the twitter node

I spent an hour tearing my hair out as to why it wasn't working and had to resort to an external change node 🙂

Can't believe after all the years working with NR that it was only when I wrote this simple flow that my errant thinking struck me. 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 November 2022 09:59 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/2 "2022-11-07T09:59:25Z")

</div>

Although, I am still suprised that it silently "fails" and doesn't give an error - why is that?

FYI here is the JS that the Blocky node generates

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/81ba3c55b781b52d85e9841aeeba4447ad6e83dc.png)

---

<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:** [7 November 2022 10:00 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/3 "2022-11-07T10:00:49Z")

</div>

If you added the following (exactly as written...) to the top of that code it wouldn't fail silently.

```auto
"use strict";

```

> why is that?

Welcome to JavaScript. 😉

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 November 2022 13:44 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/4 "2022-11-07T13:44:18Z")

</div>

Do I get a prize for spotting more than 1 error in that code 😉

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 November 2022 13:45 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/5 "2022-11-07T13:45:49Z")

</div>

You can speak Blockly? 🙂

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 November 2022 13:50 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/6 "2022-11-07T13:50:48Z")

</div>

I _can_ but the error is in the output javascript.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 November 2022 13:52 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/7 "2022-11-07T13:52:15Z")

</div>

That's just what Blocky transcribes it to - can't control that - don't care - hate JS 🙂

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [7 November 2022 14:26 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/8 "2022-11-07T14:26:13Z")

</div>

My initial answer to "What's wrong with this" was the colour clash and horrible shapes of the Blockly code. Not all non-procedural languages can have the clean UI of Node-red though.

I tried to see who did know and "liked" the post; I accidentally liked it myself.  
Yet I have not the slightest idea what's wrong with the code apart from it just feels wrong.

I followed knolleary's hint of adding "use strict"; to the Javascript, it still fails silently.

Please put me out of my misery and explain what's going on?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 November 2022 14:31 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/9 "2022-11-07T14:31:07Z")

</div>

It doesn't set msg.payload to an object  
So when it tries to set msg.payload.text - it just gets ignored and the original timestamp msg.payload gets sent on instead

This fixes it

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29845e336ff1ef6c242aa37ef73a97f0e04b386b.png)

> [@jbudd](#):
>
> I followed knolleary's hint of adding "use strict"; to the Javascript, it still fails silently.

Interesting 🙂

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [7 November 2022 14:38 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/10 "2022-11-07T14:38:40Z")

</div>

Arrghhhhh! You added some pink to all that claret and magenta. It hurts!

> [@cymplecy](#):
>
> It doesn't set msg.payload to an object

Thanks for the explanation.

---

<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:** [6 January 2023 14:38 UTC](https://discourse.nodered.org/t/what-is-wrong-with-this/70197/11 "2023-01-06T14:38:45Z")

</div>

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