Comparing version 1.0.0 to 1.1.0
10
index.js
@@ -7,5 +7,11 @@ var util = require('util'); | ||
function FastError() { | ||
this.message = util.format.apply(null, arguments); | ||
this.name = name; | ||
Error.captureStackTrace(this, arguments.callee); | ||
if (arguments[0] && arguments[0] instanceof Error) { | ||
this.message = arguments[0].message; | ||
this.stack = arguments[0].stack.replace(arguments[0].name, name); | ||
} else { | ||
this.message = util.format.apply(null, arguments); | ||
Error.captureStackTrace(this, arguments.callee); | ||
} | ||
} | ||
@@ -12,0 +18,0 @@ |
{ | ||
"name": "fasterror", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Quickly create custom error objects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,2 +45,20 @@ var fasterror = require('../index'); | ||
}); | ||
test('[error constructor] should copy message and stack from constructing error', function(assert) { | ||
var MyError = fasterror('MyError'); | ||
var sourceErr = new TypeError('bad type'); | ||
var err = new MyError(sourceErr); | ||
assert.equal(err.message, 'bad type'); | ||
assert.ok(err.stack.match(/^MyError: bad type/)); | ||
// Is set to 47:21 to indicate it came from the `TypeError` line | ||
assert.ok(err.stack.match(/error.test.js:47:21/)); | ||
assert.end(); | ||
}); | ||
test('[error constructor] should set default code for constructing error', function(assert) { | ||
var MyError = fasterror('MyError', {code: 'code'}); | ||
var sourceErr = new TypeError('bad type'); | ||
var err = new MyError(sourceErr); | ||
assert.equal(err.message, 'bad type'); | ||
assert.equal(err.code, 'code'); | ||
assert.end(); | ||
}); | ||
@@ -47,0 +65,0 @@ test('[error object] should perform string interpolation on provided arguments', function(assert) { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
5230
97
1