hookio/hook.io — Issue #147: Emitting an "error" event causes crash when no handler present, but still emits
Author: geoffreak
Created: 2012-01-01 22:16:48+00:00
State: open

I'm writing my first hook.io hooks and have come across a strange behavior. I was using an event called "error" to log error messages in a very simple logger I wrote, but was getting the following error whenever I was emitting an error (though it would still emit before crashing):

```javascript
/Users/joshua/Dropbox/Code/nodetests/hook.io/node_modules/hook.io/vendor/EventEmitter2/lib/eventemitter2.js:263
throw new Error("Uncaught, unspecified 'error' event.");
^
Error: Uncaught, unspecified 'error' event.
at [object Object]. (/Users/joshua/Dropbox/Code/nodetests/hook.io/node_modules/hook.io/vendor/EventEmitter2/lib/eventemitter2.js:263:17)
at [object Object].emit (/Users/joshua/Dropbox/Code/nodetests/hook.io/node_modules/hook.io/lib/hookio/hook.js:394:38)
at def (/Users/joshua/Dropbox/Code/nodetests/hook.io/includes/httpget.js:53:8)
at /Users/joshua/Dropbox/Code/nodetests/hook.io/includes/httpget.js:35:7
at /Users/joshua/Dropbox/Code/nodetests/hook.io/includes/httpget.js:130:8
at Object.oncomplete (/Users/joshua/Dropbox/Code/nodetests/hook.io/includes/httpget.js:136:17)
```
This is the code that triggered the crash:

```javascript
hook.emit('error', {error: err, msg: "Failed fetching " + options.url});
```
At first I wasn't sure what this was all about, but the error went away when I added the following code to the hook:

```javascript
hook.on('error', function(err, callback){
console.log(err, callback);
});
```
My guess is that "error" is a reserved keyword in EventEmitter2, but I find it very strange that it still emits anyways before crashing (just the hook that emitted the error). This is inconsistent behavior and at the very least needs to be documented so others won't have to figure out why their applications are crashing.