Is node error handling really dangerous?

I am correct in saying that a simple mistake, for example ...

arr.forEach   --> when arr is undefined

      

Will affect thread node ENTIRE? Will all users be disabled?

I'm amazed if this is the case, because of course it's insanely inconvenient. Especially if I have multiple users, all chat apps running.

And if so, how can I ensure that there are no errors in my code?

UPDATE:

I don't see auto restart as a function to work around this issue ...

+3


source to share


3 answers


You should probably use domains. Domains provide us with a way to act on error events for all event and callback emitters bound to a specific domain.

All errors are propagated to this domain without losing the context of the error. You can wrap the function in a domain call, subscribe to error events, and handle all errors in one place.



Domains ensure that your function runs in isolation and bugs don't become a process. This is a good way to prevent the node process from exiting if an error is what the application can recover from.

http://www.howtojs.org/understanding-exceptions-domains-in-nodejs/

0


source


In a browser or node, 99% of the JS execution runs a listener or handler, callback or dispatch procedure. If the listener crashes, then of course it will crash and bad things can happen, but the node (or browser) will of course continue to run and listen and dispatch.

In modern frameworks like koa, 99% of execution occurs in the context of how much sums for large try-catch constructs that just fail, possibly cause the promise to fail, and then catch the closest handler, and life will be spent.



If the error is on the main execution line, where everything gets set up or started or initialized, then yes, you're out of luck, but all you have to do is get to the point app.listen()

without crashing.

So the answer to your question is no, node error handling is actually not that dangerous.

+1


source


typeof arr === 'array'

before any iterations on dynamically created objects. Other languages ​​also crash with this exception.

-1


source







All Articles