Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new design of error handling #92

Closed
raitucarp opened this issue Dec 5, 2014 · 19 comments
Closed

new design of error handling #92

raitucarp opened this issue Dec 5, 2014 · 19 comments

Comments

@raitucarp
Copy link

What about new design of error handling? I mean, I know that node.js is single threaded, but cmon.. every uncaughtexception error, or if there is throw new error, it's close entire application, hang and crash and bam!. Domain solution is not bad, but not clear enough and give some production headache.

Is new design of error handling possible?

sorry, if this is a duplicate issue

@ghostbar
Copy link
Contributor

ghostbar commented Dec 6, 2014

I use a combination of cluster with process.on('uncaughtException'..., very similar to what's expressed here http://shapeshed.com/uncaught-exceptions-in-node/

That makes your application behave like a phenix.

@rumkin
Copy link
Contributor

rumkin commented Dec 6, 2014

@ghostbar This solution solves fail-safety problem. But not error handling.

@ghostbar
Copy link
Contributor

ghostbar commented Dec 6, 2014

@rumkin indeed, but error handling is solved on programming, not throwing errors but actually doing something with them. That's what I do at least. Very few times I have errors not being handled.

@benjamingr
Copy link
Member

@raitucarp if you promisify your code you get error handling with propagation etc for free. So - in my opinion there is a user level solution to this problem.

@rlidwka
Copy link
Contributor

rlidwka commented Dec 6, 2014

if you promisify your code

Sure. If you explain how to promisify streams and other eventemitters.

Right now domains could be used to catch any kind of errors: async, throws, error event, anything. Promises can't replace all that.

@benjamingr
Copy link
Member

Don't promisify streams and other event emitters - you can use the exact same idea though - wrap the callbacks in try/catch from the outside and propagate. It could be an interesting idea.

@ibc
Copy link

ibc commented Dec 13, 2014

What about new design of error handling? I mean, I know that node.js is single threaded, but cmon.. every uncaughtexception error, or if there is throw new error, it's close entire application, hang and crash and bam!. Domain solution is not bad, but not clear enough and give some production headache.

Just code correctly and be ready for errors before they happen (I mean: use try&catch).

No magic here, and no magic in any language. If an error happens (and the code does not manage it) then memory leak or inconsistent state may happen. Don't make the language/platform responsible of fixing that.

@raitucarp
Copy link
Author

@ibc you should read @tj medium https://medium.com/code-adventures/farewell-node-js-4ba9e7f3e52b

I believe, Io.js or node.js itself is not a language specification, error handling in platform may be redesigned

@tj
Copy link
Contributor

tj commented Dec 13, 2014

It'll be somewhat mitigated when js-land is async/await & utilizes promises at the lowest level possible. Everything built on that would be inherently more fault tolerant.

In general it's always been sort of backwards in js-land, personally I think async is the exception not the rule, so Go and friends approach of blocking by default makes more sense and is much easier to work with.

If / when core uses promises all a lot of the madness could disappear. Someone posted a diagram of how streams work in node the other day, I think that illustrates how terrible evented programming is for non-trivial problems. The Go equiv would be muchhhh easier to grok because backpressure is implicitly applied by a lack of read, no awkward propagation. (This isn't unique to Go, just using it as an example).

I've heard some weird issues with promises as well, I haven't read into that much to be honest so I can't comment there.

Not sure what the plan is going forward, seemed like lots of people still dislike the idea of core being anything but callbacks, that's the direction I'd go though. Node is already so synonymous with "tiny core that does almost nothing" so that might be hard to break.

@bodokaiser
Copy link

@tj do you really think promises will fix this? I remember some bad times debugging errors inside duo, component or koa which lay deep inside some node modules.

@benjamingr
Copy link
Member

@bodokaiser a promise implementation that's tuned towards error handling like bluebird does this a lot better than promise libraries like es6-promise since it does call stack stitching and proper error handling. Might want to check it out.

@sonewman
Copy link
Contributor

A lot of this could be solved by clearer more obvious error messages (giving a better idea of the component, which made it and why).

Then better documentation/ lookup references to these errors to give insight into developers who don't have deep knowledge of the core internals how they can mitigate the issue.

@jonathanong
Copy link
Contributor

i'm -1 to any error "solution" in core. i've been using promises/generators for a while and rarely have uncaught exceptions. i'd rather have core remain minimal and let es7 async/await solve this for us.

@rlidwka
Copy link
Contributor

rlidwka commented Dec 21, 2014

and let es7 async/await solve this for us

We don't really want to wait 20.5 years for it to be implemented in V8 properly without command-line flags... do we?

@jonathanong
Copy link
Contributor

It's more like 2 years for v8 to implement without flags and 5 years for node to update v8

@rumkin
Copy link
Contributor

rumkin commented Dec 23, 2014

I think that current js and nodejs error problem based on pure error object design which cause wick error notifications and unfair error capturing and throwing policy. There is a lot of libraries which throws deeply nested errors caused by wrong argument type of highlevel calls and a tones of malformed error objects like native nodejs ECONNRESET and so. Some libs use arrays to pass multiple errors and some use Native Object as a error report. The first step should be done in this direction.

@sonewman
Copy link
Contributor

@rumkin things like ECONNRESET are actually being thrown in the correct place and the error type/name is more of a posix thing than an io.js specific thing. It is actually the socket connection, which has thrown the error. The problem often is how to figure out what is affected by that error, and how best to mitigate that in the code affected by it.

Since it is thrown asynchronously there is only a short stack trace back to net.js, this makes it much more difficult to deal with

What I believe @jonathanong was eluding to, is that if you code with the premise of handling errors and are aware of what they are, when they could occur and how best to deal with them in your program/application. Whether these are handled them via language features (e.g. generators and promises) or just by handling the error events these can be handled accordingly.

TCP, FileSystem or other system errors just need to be understood by the developers using them, which is why I think more resources are needed to aid in educating and understanding these issues and how best to deal with them (obviously there is not always a one size fits all solution).

With regards to libraries throwing errors or using arrays of multiple errors, I think both of these things are anti-patterns and not really useful. Although new language features make it easier to deal with things, ideally the only times an error should be thrown is if one occurs and there is no handle on an error event or there is a developer code/syntax error (which I think should always throw, to prompt a code change to fix the bug). Unfortunately there is no nice way to force module developers to adopt good error construction/handling principles so personally I would just avoid these modules as best I can.

@brendanashworth
Copy link
Contributor

I think that the gist of this discussion has been that a solution in core is a no-go and that errors shouldn't be handled by the system, rather the developer. With the seemingly decreasing interest, I'll be closing this issue, but feel free to re-open it or open a new issue if you feel like it wasn't fully discussed.

Also, there is now error documentation! 😃

@raitucarp
Copy link
Author

Ok thanks @brendanashworth I still watch this issue for updates 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests