Live data from Hacker News

Zones – Robust error handling and flow control for Node.js

strongloop.com

11–20 of 22 posts

Re: Zones – Robust error handling and flow control for Node.js

#11

Earlier quoted context omitted.

> I'm having a really hard time seeing how this is an actual improvement on the status quo What we're doing is make it unnecessary to add error handlers everywhere and still get caught by surprising failure modes. If the zone catches an error it cleans up (closes resources, cancel operations when that makes sense) and then routes the error to the zone's result callback so you can handle it in once place. The 'status…

So, looking at the examples again and going back to this: > What we're doing is make it unnecessary to add error handlers everywhere and still get caught by surprising failure modes. If the zone catches an error it cleans up (closes resources, cancel operations when that makes sense) and then routes the error to the zone's result callback so you can handle it in once place. I'm really unclear on how the zone library…

> I'm really unclear on how the zone library is doing the magical interception of errors

It monkey patches the entry points into javascript from the binding layer (some wrapping happens at a higher level), for the purpose of keeping track of the active zone. At that level we also wrap a try-catch block around all callbacks.

> Does a library (say, one that came from npm and not the core library) have to be zone-aware to function correctly with zones

It depends. Most modules shouldn't need any modification. However there are certain not-so-common cases (for example, when you're implementing a connection pool) that the module would need to be made zone-aware. It's necessary when the module wants to call a callback (or any function) in a child zone from a parent/ancestor zone.

Right now that's not very easy - you'd have to use a Gate (https://github.com/strongloop/zone#gates). W're working on an easier API.

Re: Zones – Robust error handling and flow control for Node.js

#12
post #8

Earlier quoted context omitted.

> I'm having a really hard time seeing how this is an actual improvement on the status quo What we're doing is make it unnecessary to add error handlers everywhere and still get caught by surprising failure modes. If the zone catches an error it cleans up (closes resources, cancel operations when that makes sense) and then routes the error to the zone's result callback so you can handle it in once place. The 'status…

The comparison page highlights that Zone.js is better than promises because of long stack traces [1], but most promise implementations already have that [2]. I'm confused, that seems to be the only comparison to promises. Edit: Conceptually it seems the same as promises. The main difference seems to be that they've added hooks [3] into the pipeline, and they duck punch the core API to intercept errors. Bluebird has s…

Note that the comparison page doesn't have the "zone" library we just announced on it. Zone.js is conceptually a bit different and it targets browsers.

Re: Zones – Robust error handling and flow control for Node.js

#13
post #10
post #2

> We’re waiting eagerly for node v0.12 to be released. > Unfortunately, the release may not happen soon since there are about 800 open bugs and about 180 pull requests waiting to be reviewed. Is it a real problem? Seems that other popular projects like Ruby on Rails have a similar number of opened issues and it's not stopping them from releasing new versions. Does the Node core team have any plans how to prevent this…

That quote and those numbers are incredibly misleading, I'm not sure why they use that to prove Node 0.12 isn't coming soon. If you actually look at the issues on Github, only around 30 of those are marked as 0.12, with the rest being various other milestones including 0.13 and 1.0. It has also already been stated that there is only one more 0.11 release before 0.12.

No one is trying to "prove" 0.12 isn't coming soon, we've put lots of work into it, and look forward to its release, and its got some great new features.

I'm not sure the tag states are always up to date, perhaps they are, but the fact remains that 0.12 has been "real soon now" for quite a while, so saying it might be a while still is a pretty safe statement.

The core team is working hard, but I think the PR queue is a good indication of how scarce a resource review time is.

Re: Zones – Robust error handling and flow control for Node.js

#15
Any error handling that forces me to add extra lines into my code is one I see as too obstructing. First and foremost, asynchronous exception handling and propagation, and "long" stacktraces that go with it, should be a core part of the JavaScript language, and I'm personally waiting for that to happen at some point. In the meantime, the best solution I was able to come up with is "LAEH2". See it here: https://github.com/ypocat/laeh2

Re: Zones – Robust error handling and flow control for Node.js

#16
post #10

Earlier quoted context omitted.

That quote and those numbers are incredibly misleading, I'm not sure why they use that to prove Node 0.12 isn't coming soon. If you actually look at the issues on Github, only around 30 of those are marked as 0.12, with the rest being various other milestones including 0.13 and 1.0. It has also already been stated that there is only one more 0.11 release before 0.12.

No one is trying to "prove" 0.12 isn't coming soon, we've put lots of work into it, and look forward to its release, and its got some great new features. I'm not sure the tag states are always up to date, perhaps they are, but the fact remains that 0.12 has been "real soon now" for quite a while, so saying it might be a while still is a pretty safe statement. The core team is working hard, but I think the PR queue is…

The way it is stated assumes that 0.12 won't be coming until all issues and pull requests are closed, which clearly is not the case.

Re: Zones – Robust error handling and flow control for Node.js

#17
Looking through the Zone API documentation, this is a reimplementation of what most Promise libraries already provide (Zones even support "then" and "catch" methods, but don't follow the chaining standard). The only new feature is "Gates," which the documentation admits are awkward and need to be revisited — and many Promise libraries already provide simple mechanisms for sharing resources similar to what Gates allow, but with more-consistent APIs. Zones also don't work several important Node-core libraries (cluster, fs, zlib, and more), whereas Promise libraries solved interop long ago.

Promises/A+ is already standardized and is shipping in browsers. Yes, Promises/A+ is more complicated than it needs to be, and I wish a simpler, more monadic approach had won out. But this is an unnecessary flow-control fork, and it's not even a particularly good one by comparison. If Zones were built on top of the ES6 standard, all ES6-compatible promise libraries would immediately work with it (and there are many mature ones that already exist). No existing libraries work with Zones, and the existing ones will need to be amended to add Zone-specific interop.

God knows nobody needs a zone-to-promise converter; there are enough ways to do asynchronous flow control as it stands. This blog post seems to hope that Zones will some day make it into Node core; I sincerely hope they don't in their current state.

Re: Zones – Robust error handling and flow control for Node.js

#18

Looking through the Zone API documentation, this is a reimplementation of what most Promise libraries already provide (Zones even support "then" and "catch" methods, but don't follow the chaining standard). The only new feature is "Gates," which the documentation admits are awkward and need to be revisited — and many Promise libraries already provide simple mechanisms for sharing resources similar to what Gates allow…

I'm sorry if it wasn't clear enough from the blog, but the attempt here is not to write a flow control library that solves the callback hell problem like promises does.

You should think of it more as an asynchronous try-catch block, where resources created in the "try" block are automaticially cleaned up.

I believe that flow control in the future will be done with generators; check out https://github.com/visionmedia/co for example.

Re: Zones – Robust error handling and flow control for Node.js

#19

Looking through the Zone API documentation, this is a reimplementation of what most Promise libraries already provide (Zones even support "then" and "catch" methods, but don't follow the chaining standard). The only new feature is "Gates," which the documentation admits are awkward and need to be revisited — and many Promise libraries already provide simple mechanisms for sharing resources similar to what Gates allow…

I'm sorry if it wasn't clear enough from the blog, but the attempt here is not to write a flow control library that solves the callback hell problem like promises does. You should think of it more as an asynchronous try-catch block, where resources created in the "try" block are automaticially cleaned up. I believe that flow control in the future will be done with generators; check out https://github.com/visionmedia/…

Okay. But Promises already provide asynchronous try/catch blocks, and you could have used those as the basis of your API (and as first-class objects that get returned), rather than inventing a new API and set of objects.

> I believe that flow control in the future will be done with generators; check out https://github.com/visionmedia/co for example.

Generators and promises are both types of flow control that will be used in the future: they're both in the ES6 standard. In fact, visionmedia/co already supports promises.

Re: Zones – Robust error handling and flow control for Node.js

#20

Earlier quoted context omitted.

I'm sorry if it wasn't clear enough from the blog, but the attempt here is not to write a flow control library that solves the callback hell problem like promises does. You should think of it more as an asynchronous try-catch block, where resources created in the "try" block are automaticially cleaned up. I believe that flow control in the future will be done with generators; check out https://github.com/visionmedia/…

Okay. But Promises already provide asynchronous try/catch blocks, and you could have used those as the basis of your API (and as first-class objects that get returned), rather than inventing a new API and set of objects. > I believe that flow control in the future will be done with generators; check out https://github.com/visionmedia/co for example. Generators and promises are both types of flow control that will be…

A Zone object could be a "subclass" of a Promise. It's something I have considered but I didn't think it'd be necessary for the first release.

> But Promises already provide asynchronous try/catch blocks

They do, if all you use is modules that return promises, and the node ecosystem currently has many modules that don't. For example:

    zone.create(function MyZone() {
      // Within MyZone
      setTimeout(function() {
        // Within MyZone
        throw new Error("Oh noes!");
      });
    }).catch(function(err) {
      // Back in the parent zone.
      // Handle the error here.
    });
The above won't work with promises unless you use a promisified version of setTimeout and return that promise from the constructor function.

Conversely, with zones, chaining callbacks is hard to define conceptually:

    zone.create(function MyZone() {
      // In MyZone
    }).then(function() {
      // Which zone are we in?
    }).then(function() {
      // Which zone are we in?
    });
But if you have a great idea here, bring it on.
Post reply on HN