Comparing version 0.1.5 to 0.1.6
@@ -18,3 +18,3 @@ var prr = require('prr') | ||
if (Error.captureStackTrace) | ||
Error.captureStackTrace(this, arguments.callee) | ||
Error.captureStackTrace(this, this.constructor) | ||
init.call(this, 'CustomError', message, cause) | ||
@@ -41,3 +41,3 @@ } | ||
if (Error.captureStackTrace) | ||
Error.captureStackTrace(this, arguments.callee) | ||
Error.captureStackTrace(this, err) | ||
} | ||
@@ -44,0 +44,0 @@ err.prototype = !!proto ? new proto() : new CustomError() |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"main": "errno.js", | ||
@@ -22,2 +22,4 @@ "dependencies": { | ||
"devDependencies": { | ||
"error-stack-parser": "^2.0.1", | ||
"inherits": "^2.0.3", | ||
"tape": "~4.8.0" | ||
@@ -31,4 +33,4 @@ }, | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "node --use_strict test.js" | ||
} | ||
} |
54
test.js
@@ -1,6 +0,6 @@ | ||
#!/usr/bin/env node | ||
var test = require('tape') | ||
, inherits = require('inherits') | ||
, ErrorStackParser = require('error-stack-parser') | ||
, errno = require('./') | ||
var test = require('tape') | ||
, errno = require('./') | ||
test('sanity checks', function (t) { | ||
@@ -23,4 +23,4 @@ t.ok(errno.all, 'errno.all not found') | ||
test('custom errors', function (t) { | ||
var Cust = errno.create('FooNotBarError') | ||
var cust = new Cust('foo is not bar') | ||
const Cust = errno.create('FooNotBarError') | ||
const cust = new Cust('foo is not bar') | ||
@@ -33,1 +33,43 @@ t.equal(cust.name, 'FooNotBarError', 'correct custom name') | ||
}) | ||
test('callstack', function (t) { | ||
const MyError = errno.create('MyError') | ||
function lastFunction (ErrorType, cb) { | ||
process.nextTick(cb, new ErrorType('oh noes!')) | ||
} | ||
function secondLastFunction (ErrorType, cb) { | ||
lastFunction(ErrorType, cb) | ||
} | ||
function testFrames (t) { | ||
return function (err) { | ||
const stack = ErrorStackParser.parse(err) | ||
t.same(stack[0].functionName, 'lastFunction', 'last stack frame ok') | ||
t.same(stack[1].functionName, 'secondLastFunction', 'second last stack frame ok') | ||
t.end() | ||
} | ||
} | ||
t.test('custom error, default prototype', function (t) { | ||
secondLastFunction(MyError, testFrames(t)) | ||
}) | ||
t.test('custom error, custom prototype', function (t) { | ||
const MyError2 = errno.create('MyError2', MyError) | ||
secondLastFunction(MyError2, testFrames(t)) | ||
}) | ||
t.test('custom error, using inheritance', function (t) { | ||
const CustomError = errno.custom.CustomError | ||
function MyError3 (message, cause) { | ||
CustomError.call(this, message, cause) | ||
} | ||
inherits(MyError3, CustomError) | ||
secondLastFunction(MyError3, testFrames(t)) | ||
}) | ||
}) |
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
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
17596
464
0
3