# Need help taking this message apart and making a new one

**URL:** <https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983>\
**Category:** General\
**Created:** [20 May 2020 09:45 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983 "2020-05-20T09:45:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 May 2020 09:45 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983/1 "2020-05-20T09:45:33Z")

</div>

This is the error message I get:

```auto
{"_msgid":"95a5f34b.89b7f","topic":"ERROR_REPORT/BedPi/Logging/","error":{"message":"ReferenceError: a is not defined (line 1, col 19)","source":{"id":"f15d59f6.b745","type":"function","name":"This will throw an error","count":1}},"_error":{},"time":"2020-05-20 19:41:31","payload":"Cause an error"}

```

I am wanting to create a message showing the error which can be written to a text file - human readable.

This is the code I have so far:

```auto
let when = msg.time;
let who = msg.topic;
let what = msg.error;
let where = msg.error.source;

node.warn("What " + what);
node.warn("Where " + where);

msg.payload = "When " + when + "\nWho " + who + "\nWhat " + what + "\nWhere " + where;

return msg;

```

But I get this as the output:

```auto
When 2020-05-20 19:41:31Who ERROR_REPORT/BedPi/ERROR_REPORT/BedPi/Logging/What [object Object]Where [object Object]

```

I'm messing up with the objects. I know.

This is a big (huge) re-write of a lot of code as I finally discovered that what I had doesn't work.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 May 2020 09:50 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983/2 "2020-05-20T09:50:35Z")

</div>

I'm stupid.

Worked it out with this:

```auto
let when_ = msg.time;
let who_ = msg.topic;
let what_ = msg.error.message;
let where_ = msg.error.source.id;

node.warn("What " + what_);
node.warn("Where " + where_);

msg.payload = "When " + when_ + "\nWho " + who_ + "\nWhat " + what_ + "\nWhere " + where_;

return msg;

```

---

<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:** [20 May 2020 09:52 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983/3 "2020-05-20T09:52:20Z")

</div>

Are you using node-red-contrib-flogger?

You can simply pass an object to it & it'll add the whole msg object (as JSON) into a file - no fuss, no muss.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 May 2020 09:58 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983/4 "2020-05-20T09:58:50Z")

</div>

Never heard of that.

(Dumb question) would it be better for me for this single use?

I have since added more stuff to the code to again make it more readable.  
But not to the point of _rocket science_.

I may have a peep at the node, but was just wondering about its _overheads_.

---

<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:** [3 June 2020 09:58 UTC](https://discourse.nodered.org/t/need-help-taking-this-message-apart-and-making-a-new-one/26983/5 "2020-06-03T09:58:51Z")

</div>

Closed on 3 June 2020 09:58 UTC

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