You missed the point of the example about domain nesting failing.

`err.errors` is a mongoose thing, not a trycatch thing. It was my attempt
at a plausible uncaught exception in the strained example. The original
gist was correct:
https://gist.github.com/4075562/4c0e389da3e15048c2c99629eca28b8d96a7ebad

Nonetheless, the point stands that domain nesting doesn't work and the
process dies if you have an async error in a callback coming from a library
that uses domains, and had any sort of internal failure, a use-case in
which trycatch handles seemlessly.

Or to put it another way, it's not possible with domains (AFAIK) for
`domainFoo` to return an Error to its callback if the 3rd-party library
uses domains to return async errors, and as I mentioned in the other
thread, this is my primary use-case for async error-handling.

Also, FWIW, I'm highly critical of domains for all the reasons stated
above, but I also very much want a solution to the problem they solve. My
recommended solution (with code) is trycatch, and as you can see from this
thread, I'm not the only one that would prefer a much cleaner, simpler
solution to error handling in node.js.

That being said, I think node.js' error handling problem boils down to an
inability to catch asynchronous exceptions reliably, something
that's exacerbated by the lack of maturity of most 3rd-party libraries and
node.js' threadlessness and concurrency. uncaughtException is insufficient
as it loses context, and domains (at least currently) are insufficent for
the reasons stated above.

Cheers,
Adam Crabtree


On Wed, Nov 14, 2012 at 3:37 PM, Forrest L Norvell <[email protected]>wrote:

> On Wednesday, November 14, 2012 at 3:26 PM, Adam Crabtree wrote:
>
> FWIW, this is exactly why I built trycatch (
> https://npmjs.org/package/trycatch). trycatch works for all the use cases
> listed here:
>
> * Call once, and all proceeding async calls and uncaught exceptions are
> properly handled
> * Nesting works as expected (exactly how nesting synchronous try/catch
> blocks would behave)
> * Not reliant on 3rd party modules to implement in order to work
> * Long stack traces
> * Works properly with EventEmitter
>
> Granted, trycatch ATM doesn't offer the resource cleanup, but in theory it
> could be combined with domains to accomplish this just fine. I may do so
> when I get the chance now that domains are little more stable, assuming
> they wouldn't interfere. In the other thread you mentioned above (
> https://groups.google.com/forum/?fromgroups#!topic/nodejs/RphMf98jcgA)
> where I'm discussing a few of these things, I included the following
> example where domain nesting fails, but succeeds just fine with trycatch:
>
> https://gist.github.com/4075399
>
> Nothing against domains. I just find them to be cumbersome and to not
> solve the problems I face, esp. wrt. libraries not properly handling
> Errors/exceptions.
>
> I made a few changes to your gist (the error wasn't getting handed off
> properly, and the domain error-handling code was looking for the properties
> that trycatch adds to the Error object):
>
>   https://gist.github.com/4075562
>
> In this example, everything behaves as it should (I believe) -- domainFoo
> calls thirdPartyFoo, so thirdPartyFoo's domain is active when the error is
> raised, and handles it, and then the callbacks are invoked, with the error
> ending up in the callback passed to domainFoo, as it should. Did my changes
> alter the point you were trying to make? If so, how?
>
> F
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>



-- 
Better a little with righteousness
       than much gain with injustice.
Proverbs 16:8

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to