Throwing errors - help please

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

(I need a new brain.)

Steve, I am so sorry.

This works.

Or it seems to.

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.

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

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.

1 Like

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.

I think you could simply add a property to the msg

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
1 Like

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.

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.

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

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

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

1 Like

Ah!

Ok, yeah.

Shall try now.
(Hang on.)
:slight_smile:

:frowning:
No sorry, same.

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.

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.

1 Like

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.

I had maybe call it solved here.

Again: Thanks for the help.

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