github/hubot — pull request #624 by technicalpickles (2013-12-31 17:57:21+00:00)
Title: Stop crashing on errors, and provide an API for publishing & subscribing to errors

Previously, hubot would crash for uncaught exceptions. There is `try/catch` logic around invoking listeners, but this only catches errors from synchronous code, anything asynchronous would be uncaught.

This PR includes:

* API for specifying error handlers in hubot scripts
* An 'error' event type that can be emitted, and is consumed by any error handlers
* A `process.on 'uncaughtException'` handler to emit errors through these error handlers
* Documentation for the above

It's worth noting that the [uncaughtExeption handler documentation](http://nodejs.org/api/process.html#process_event_uncaughtexception) says:

> Note that uncaughtException is a very crude mechanism for exception handling and may be removed in the future.
>
> Don't use it, use domains instead. If you do use it, restart your application after every unhandled exception!
>
> Do not use it as the node.js equivalent of On Error Resume Next. An unhandled exception means your application - and by extension node.js itself - is in an undefined state. Blindly resuming means anything could happen.
>
> Think of resuming as pulling the power cord when you are upgrading your system. Nine out of ten times nothing happens - but the 10th time, your system is bust.
>
> You have been warned.

So, it's pretty scary for sure. We've been using it internally our our own hubot for 6 months or so. Ideally, we'd use domains, but they are considered [unstable according to the docs](http://nodejs.org/api/domain.html) and also would mean we'd have to bump the node.js requirement. Certainly possible, but would require a major version bump.