Permalink
Browse files

Respect name in stack trace.

This makes sure to set the name before doing `Error.call(error)` and capturing
the stack trace so the user-provided name is reflected in the stack trace
instead of the generic `Error: ...`.
  • Loading branch information...
1 parent 19dad0c commit d1756bbf93706ab6a56334e59f7b3e39b31730bb @brianloveswords brianloveswords committed Jul 14, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/errs.js
  2. +7 −1 test/errs-test.js
View
@@ -96,7 +96,7 @@ exports.create = function createErr(type, opts) {
error = new (ErrorProto)(message);
if (!error.name || error.name === 'Error') {
- error.name = ErrorProto.name || 'Error';
+ error.name = (opts && opts.name) || ErrorProto.name || 'Error';
}
//
View
@@ -45,7 +45,13 @@ vows.describe('errs').addBatch({
"no parameters": macros.create.string('An error as a string'),
"an object": {
"that has no message": macros.create.object(opts[0]),
- "that has a message": macros.create.object(opts[1])
+ "that has a message": macros.create.object(opts[1]),
+ "that has a name": {
+ topic : errs.create({name: 'OverflowError'}),
+ "should respect that name in the stack trace" : function (err) {
+ assert.match(err.stack, /^OverflowError/);
+ },
+ }
},
"an error": macros.create.err(new Error('An instance of an error')),
"a function": macros.create.fn(function () {

0 comments on commit d1756bb

Please sign in to comment.