typed-errors
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "typed-errors", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Create custom error types that work with `instanceof` and have stack traces", | ||
@@ -19,2 +19,3 @@ "license": "BSD-2-Clause", | ||
"dependencies": { | ||
"underscore": "^1.8.3" | ||
}, | ||
@@ -21,0 +22,0 @@ "devDependencies": { |
@@ -1,12 +0,18 @@ | ||
var makeTypedError = function (name) { | ||
var _ = require('underscore'); | ||
var makeTypedError = function (name, Supertype) { | ||
Supertype = Supertype || Error; | ||
var TypedError = function (message) { | ||
var sup = new Supertype(message); | ||
_(this).extend(sup); | ||
this.name = name; | ||
this.message = message; | ||
var tempStack = (new Error()).stack; | ||
// replace 'Error' with actual name in stack trace | ||
this.stack = this.name + tempStack.slice(5); | ||
this.stack = sup.stack.replace(/^[^:]+:/, name + ':'); | ||
}; | ||
TypedError.prototype = Object.create(Error.prototype); | ||
TypedError.prototype = Object.create(Supertype.prototype); | ||
TypedError.prototype.constructor = TypedError; | ||
@@ -13,0 +19,0 @@ |
@@ -11,3 +11,3 @@ require('should'); | ||
try { | ||
throw new FooException('Foobar!'); | ||
throw new FooException('Exn_Message'); | ||
} catch (e) { | ||
@@ -22,3 +22,3 @@ e.should.be.an.instanceof(FooException); | ||
try { | ||
throw new FooException('Foobar!'); | ||
throw new FooException('Exn_Message'); | ||
} catch (e) { | ||
@@ -31,5 +31,5 @@ e.should.not.be.an.instanceof(CopyOfFooException); | ||
try { | ||
throw new FooException('Foobar!'); | ||
throw new FooException('Exn_Message'); | ||
} catch (e) { | ||
e.message.should.equal('Foobar!'); | ||
e.message.should.equal('Exn_Message'); | ||
} | ||
@@ -40,6 +40,6 @@ }); | ||
try { | ||
throw new FooException('Foobar!'); | ||
throw new FooException('Exn_Message'); | ||
} catch (e) { | ||
// starts with correct name and where it was thrown from | ||
e.stack.should.match(/^FooException\n {4}at new TypedError \(\S+make-typed-error.js:\d+:\d+\)/); | ||
e.stack.should.match(/^FooException: Exn_Message\n {4}at new TypedError \(\S+make-typed-error.js:\d+:\d+\)/); | ||
// eventually points to where it was thrown in this very file | ||
@@ -46,0 +46,0 @@ e.stack.should.match(/\(\S+make-typed-error.spec.js:\d+:\d+\)/); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6216
57
1
+ Addedunderscore@^1.8.3
+ Addedunderscore@1.13.7(transitive)