# Throwing errors - help please

**URL:** <https://discourse.nodered.org/t/throwing-errors-help-please/85388>\
**Category:** General\
**Created:** [9 February 2024 22:35 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388 "2024-02-09T22:35:03Z")\
**Posts on this page:** 12\
**Page:** 2

<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:** [11 February 2024 10:11 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/21 "2024-02-11T10:11:05Z")

</div>

> [@Trying\_to\_learn](#):
>
> That takes what your code gives me and gets/extracts the subflow's ID.  
> Then that is used.
> 
> So taking that code..... Why doesn't it work in the subflow

In what way? Please show us what your node.warn and errors are showing you. And explain what you expect it is not right.

---

<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:** [11 February 2024 10:13 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/22 "2024-02-11T10:13:27Z")

</div>

(I need a new brain.)

Steve, I am so sorry.

This works.

Or it seems to.

```auto
const id = env.get("NR_NODE_PATH")

if (msg.delay == undefined) {
    //
    let ids = id.split("/");
    node.warn("IDS = " + ids);
    const errr = `msg.delay not set in message going into ` + ids[1];
    node.error(errr,msg);
    return;
}
return msg;

```

I get ONLY the subflow's ID in the error message.

I really don't help myself leaving old stuff in while working.

But I would like to get a second set of eyes that I am still not shooting myself in the foot.  
And this will work on 3.0.x NR.

 ![Screenshot from 2024-02-11 21-14-52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2ff61633b3a1377d122700f699268fad519c3c8b.png)

---

<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:** [11 February 2024 10:20 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/23 "2024-02-11T10:20:27Z")

</div>

> [@Trying\_to\_learn](#):
>
> ```auto
> const id = env.get("NR_NODE_PATH")
> 
> if (msg.delay == undefined) {
> //
> let ids = id.split("/");
> node.warn("IDS = " + ids);
> const errr = `msg.delay not set in message going into ` + ids[1];
> node.error(errr,msg);
> return;
> }
> return msg;
> 
> ```

It looks fine to me. I'd probably tweak it to be...

```javascript
if (msg.delay == undefined) {
    const id = env.get("NR_NODE_PATH")
    const ids = id.split("/")
    node.warn({error_path: ids})
    const errr = `msg.delay not set in message going into ${ids[1]}`
    node.error(errr, msg)
    return
}
return msg

```

Functionally no different, just a bit more concise IMO.

---

<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:** [11 February 2024 10:23 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/24 "2024-02-11T10:23:18Z")

</div>

# THANK YOU

I am not having a good time just now....

(Not wanting to sound ungrateful)

The only thing that would be even better is if that _value_ `ids[1]` could be put in `error.source.id`  
But that may be pushing the friendship with NR (and maybe you).  
Me asking all these difficult questions - and for an older version of NR too.

---

<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:** [11 February 2024 10:26 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/25 "2024-02-11T10:26:31Z")

</div>

I think you could simply add a property to the msg

```js
if (msg.delay == undefined) {
    const id = env.get("NR_NODE_PATH")
    const ids = id.split("/")
    node.warn({error_path: ids})
    const errr = `msg.delay not set in message going into ${ids[1]}`
    msg.source = ids[1]
    node.error(errr, msg)
    return
}
return msg

```

---

<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:** [11 February 2024 10:28 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/26 "2024-02-11T10:28:01Z")

</div>

Oh, ok.

I wasn't sure if those parts were _editable_ by the user.  
They were set by the system determined by the originating node.

(The path is not quite right, but I get what you mean. Thanks)

Interesting.

Your code (well, that extra line) added and put in.

The `node.warn` is kind of handy.

 ![Screenshot from 2024-02-11 21-33-51](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59ccc837cb66092678dfc104d3d7ac4757cc7a41.png)

Brown box/line is the `node.warn`.  
So I press the `inject` node.  
You see the 3 parts of the `ids` after being `split`.  
But somehow the `error.source.id` gets _corrupted_ with that extra stuff (see red underline)  
Not a big deal.  
As the id is also shown just above (sorry I didn't point to it) that is enough.  
I was being overly lazy to try and make a field like most other nodes that I can/could copy to paste in the `search` field.

Thoughts?  
But please, don't if you have other stuff to do.  
This is a long way from where I was originally.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2024 10:40 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/27 "2024-02-11T10:40:09Z")

</div>

> [@Trying\_to\_learn](#):
>
> `if (msg.delay == undefined) {`

You must use `===` for this to work, otherwise null will also pass the test, and possibly other falsy values. Try this code to see it

```auto
let n = null
if (n == undefined) {
    node.warn("null == undefined")
}

```

In fact it is better to use typeof  
`if (typeof msg.delay === "undefined") {`

---

<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:** [11 February 2024 10:40 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/28 "2024-02-11T10:40:58Z")

</div>

Ah!

Ok, yeah.

Shall try now.  
(Hang on.)  
🙂

☹  
No sorry, same.

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

And the `id` is still corrupted.

Ah, as I said, I am getting the needed, I just need to be careful with cutting only the right part and pasting it.

(As it will be all over the place and if one isn't getting a `delay` value....)

But - of course - now I've fixed all those problems.  
This is me trying to be a good person so if ever I give it to someone else it has a bit more _bullet proofing_ for them.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2024 10:55 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/29 "2024-02-11T10:55:03Z")

</div>

I wasn't suggesting that it would fix your problem, I was just pointing out that you test for undefined was not safe, it would give undefined for cases that were in fact defined, such as null.

---

<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:** [11 February 2024 10:56 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/30 "2024-02-11T10:56:31Z")

</div>

Sorry.

Got hung up on the problem.

But thanks.

This is another thing I need to keep in mind when writing stuff.  
It is better to try and _fall forward_ and learn the tricks to better coding.

But I fear I am still very near the bottom (maybe a couple of rungs up) of the ladder.

---

<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:** [11 February 2024 10:58 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/31 "2024-02-11T10:58:03Z")

</div>

I had maybe call it solved here.

Again: Thanks for the help.

---

<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:** [25 February 2024 10:58 UTC](https://discourse.nodered.org/t/throwing-errors-help-please/85388/32 "2024-02-25T10:58:17Z")

</div>

Closed on 25 February 2024 10:58 UTC

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

[Previous page](https://discourse.nodered.org/t/throwing-errors-help-please/85388.md?page=1)
