# Stuck simulating errors. (try 2)

**URL:** <https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050>\
**Category:** General\
**Created:** [29 September 2019 11:20 UTC](https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050 "2019-09-29T11:20:50Z")\
**Posts on this page:** 4\
**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:** [29 September 2019 11:20 UTC](https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050/1 "2019-09-29T11:20:50Z")

</div>

I have had a few problems recently and it is the routine that has bitten me on the b\*m.

And typically it is the error routine which is at fault.

To try and catch the error, and find the problem I separated the two parts and now want to inject a control signal to simulate the error.

(Actually)  
Skip to bottom it may be more important.

This is a test error message I want to inject:

```auto
{"message":"ReferenceError: a is not defined (line 1, col 19)","source":{"id":"c552872d.7f144","type":"function","name":"This will throw an error","count":1}}

```

Cut from the `debug` node.

I am trying to set up a `function` node to inject it but I can't get it working.

I know it is stupid me not understanding how to do it, but . . . . .

When I put it in an `inject` node then pass it to a `function` node, I generate infinite errors.  
(If it is actually in the flow)

Could someone help me find the elephant?

```auto
[{"id":"39bbd9ef.ce813e","type":"function","z":"accbdb61.d75918","name":"","func":"msg = {\"message\":\"ReferenceError: a is not defined (line 1, col 19)\",\"source\":{\"id\":\"c552872d.7f144\",\"type\":\"function\",\"name\":\"This will throw an error\",\"count\":1}}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":230,"wires":[[]]},{"id":"96ab98ce.848a8","type":"inject","z":"accbdb61.d75918","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":230,"wires":[["39bbd9ef.ce813e"]]}]

```

All that aside:  
The underlying problem is that I am trying to catch errors.  
When I do, usually (maybe originally) it worked.

By doing something innocent I have messed things up.

I can't catch the errors now because when I catch them, that in itself causes an error.

Thus: run away errors.

How can I catch the errors if doing that generates errors itself?

I can post that part of the flow if you want.

---

<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:** [29 September 2019 11:33 UTC](https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050/2 "2019-09-29T11:33:03Z")

</div>

Just speaking out of top of my head but I wouldn't have thought you could simulate the error you are seeing in your debug node.

(unless someone has told you differently of course)

---

<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:** [29 September 2019 11:39 UTC](https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050/3 "2019-09-29T11:39:15Z")

</div>

Errr...... I think I can.

For the sake of it this is the code I used:

```auto
var n = 23 + 56 / a;
//var n = 23 + 56 ;
msg.payload = n;
return msg;

```

But that is just to create a generic error.

Really if a real error happens, it could be anything.

So I am not sure this is really . . . . ._important_ other than I need it to test the flow.

So I created that error but _as is_ it locks up the machine.

I finally found the problem. Kinda.

So I cut the flow apart.

I want to inject that error to see what is happening to cause the error feed-back loop.

So I need to inject it _correctly_.

But when I put that in a `function` node, that in itself errors. Which shouldn't. It is just a message.

So I'm missing something.

---

<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:** [29 September 2019 11:50 UTC](https://discourse.nodered.org/t/stuck-simulating-errors-try-2/16050/4 "2019-09-29T11:50:35Z")

</div>

(ARGH!)

Found it!

From the other night - thread.

What didn't help was that I lost a couple of backups and used an older version.

Though while I was updating, I thought I was smart and archived a part of the flow.

I imported that while updating and only after the past hour of chasing my tail, I realised the problem.

Sorry folks.
