# Catch errors during flow deployment

**URL:** <https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096>\
**Category:** Developing Nodes\
**Created:** [19 September 2020 19:58 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096 "2020-09-19T19:58:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [19 September 2020 19:58 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/1 "2020-09-19T19:58:45Z")

</div>

Hello,

I'm currently writing a node that has to emit an error under certain circumstances (not as part of handling an input message). For this I'm using the node.error() function passing in an error message and as second argument an object with details of the error. I observed that catching the error with a catch node didn't work, the error was always only logged to the debug sidebar and the console. Then I realized that this happens only during early node start, i.e. when the flow is still being deployed, because when I delayed calling the error() function by e.g. 2s, catching the error with the catch node worked. I assume that the problem happens because at the time I emit the error (without delay), the flow is not completely deployed and the catch node is possibly not yet started.

So my question is: is there a possibility that a node is informed when the flow is completely deployed in order to know when the error() function can be called? I don't want to utilize above described delay, this sounds like a workaround which might also not work in all situations (e.g. when deploying the flow takes even longer than the delay time) and I also have situations where I emit the error anyway at a later time, so the delay would be unnecessary in this case.

---

<div class="post-metadata">

**Author:** ![cinhcet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cinhcet/32/438_2.png) [@cinhcet](https://discourse.nodered.org/u/cinhcet)\
**Post date:** [19 September 2020 21:43 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/2 "2020-09-19T21:43:21Z")

</div>

I have run into that a couple of times as well and wished that there was an event like `flow started`.

There are a few things to consider here:

- should this event be on a flow basis or also global?
- What about configuration nodes?
- How to deal with nodes that do asynchronous things in their constructor?
- What about partial deploys?

I guess a solution to this would be to have a `done` callback in the constructor (or as an argument for `RED.nodes.createNode`) and then two events `flow started` and `all flows started`, which fire only once if that particular node has been redeployed.

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [20 September 2020 08:44 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/3 "2020-09-20T08:44:00Z")

</div>

Yes, that makes sense. If the Node-RED runtime does not know when the nodes have finished initialization, it cannot provide the information, when flow deployment has completed. Maybe something like you proposed will be implemented in future.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2020 09:55 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/4 "2020-09-20T09:55:24Z")

</div>

what does "finished initialisation" actually mean ? If the node is one that sets up links to a remote database for example then is it finished when it starts to try to connect ? only when it has a successful connection ? If it doesn't connect correctly and times out then has it "initialised" (as the flow won't work at that point)... Do we block the whole flow from starting waiting for a node to connect to something that doesn't exist ?

---

<div class="post-metadata">

**Author:** ![cinhcet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cinhcet/32/438_2.png) [@cinhcet](https://discourse.nodered.org/u/cinhcet)\
**Post date:** [20 September 2020 10:10 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/5 "2020-09-20T10:10:22Z")

</div>

I view that similarly to the `done` callback in the closing of the node.  
It is the responsibility of the node developer to postpone calling `done` in an asynchronous part of the code only if absolutely necessary. Furthermore, there should be a timeout like in the closing of a node.  
This means that one should NOT use this to wait for establishing a connection to a remote database.  
However, knowing that now all essential node constructors have been called, one could for example establishing a connection to a remote database after the `flow started` event, meaning that if the connection is then established, it is ensured that a status or catch node can be notified.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2020 10:25 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/6 "2020-09-20T10:25:22Z")

</div>

and indeed we do have nodes-started event that is called when all constructors have been called... but as we know that doesn't mean they are all running at that point as they all start asynchronously.

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [20 September 2020 15:42 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/7 "2020-09-20T15:42:28Z")

</div>

Would this help in case of the catch nodes, i.e. are the catch nodes ready when this event is fired?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2020 15:44 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/8 "2020-09-20T15:44:55Z")

</div>

no - apparently not.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [21 September 2020 14:48 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/9 "2020-09-21T14:48:37Z")

</div>

A [similar issue](https://discourse.nodered.org/t/getting-the-initial-status-of-nodes/22162) arises at startup when a node displays its status before a `status` node is ready to receive it. This can mean that a flow that should be triggered by that status message will not start or that a dashboard item showing the node status may not be correct. The only obvious remedy seems to be giving priority to the `status` and `catch` nodes when the flow is deployed, and I don't know where that stands.

---

<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:** [20 November 2020 14:48 UTC](https://discourse.nodered.org/t/catch-errors-during-flow-deployment/33096/10 "2020-11-20T14:48:38Z")

</div>

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