diff --git a/ERR.js b/ERR.js index c5ab510..e7e32c2 100644 --- a/ERR.js +++ b/ERR.js @@ -46,18 +46,12 @@ module.exports = function (err, callback) err = new Error(err); } - //there is a callback, lets call it + //if a callback is passed, lets call it if(callback != null) { callback(err); } - //no callback, throw the error - else - { - throw err; - } } - //return true if an error happend - return err != null; + return err; } diff --git a/README.md b/README.md index 979462f..4c3ccdd 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,6 @@ var ERR = require("async-stacktrace"); The parameters of `ERR()` are: 1. `err` The error object (can be a string that describes the error too) -2. `callback` (optional) If the callback is set and an error is passed, it will call the callback with the modified stacktrace. Else it will throw the error +2. `callback` (optional) If the callback is set and an error is passed, it will call the callback with the modified stacktrace. Otherwise it will do nothing (the caller can pass the returned `err` object to the callback if desired). -The return value is true if there is an error. Else its false +The return value is the `err` object passed as the first parameter (if it was passed as a string, it will be returned as a first-class `Error()` object). diff --git a/tests.js b/tests.js index 11b1756..bb694dd 100644 --- a/tests.js +++ b/tests.js @@ -20,13 +20,13 @@ vows.describe('ERR function').addBatch({ } }).addBatch({ 'when you call it without an error' : { - 'it returns false' : function() { - assert.isFalse(ERR()); + 'it returns falsy' : function() { + assert(!ERR()); } }, 'when you call it with an error' : { - 'it returns true' : function() { - assert.isTrue(ERR(new Error(), emptyFunc)); + 'it returns truthy' : function() { + assert(ERR(new Error(), emptyFunc)); } }, 'when you give it a callback and an error': { @@ -37,19 +37,11 @@ vows.describe('ERR function').addBatch({ } }, 'when you give it no callback and an error': { - 'it throws the error' : function() { + 'it returns the error (so it can be passed to the callback)' : function() { var wasThrown = false; - try - { - ERR(new Error()); - } - catch(e) - { - wasThrown = true; - } - - assert.isTrue(wasThrown); + var err = new Error(); + assert.equal(ERR(err), err); } }, 'when you call it with a string as an error' : {