aboutsummaryrefslogtreecommitdiff
path: root/node_modules/errno
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/errno')
-rw-r--r--node_modules/errno/custom.js10
-rw-r--r--node_modules/errno/package.json6
-rw-r--r--[-rwxr-xr-x]node_modules/errno/test.js69
3 files changed, 73 insertions, 12 deletions
diff --git a/node_modules/errno/custom.js b/node_modules/errno/custom.js
index 7be16c1e4..ca8c1d8dc 100644
--- a/node_modules/errno/custom.js
+++ b/node_modules/errno/custom.js
@@ -1,13 +1,15 @@
var prr = require('prr')
function init (type, message, cause) {
+ if (!!message && typeof message != 'string') {
+ message = message.message || message.name
+ }
prr(this, {
type : type
, name : type
// can be passed just a 'cause'
, cause : typeof message != 'string' ? message : cause
- , message : !!message && typeof message != 'string' ? message.message : message
-
+ , message : message
}, 'ewr')
}
@@ -15,7 +17,7 @@ function init (type, message, cause) {
function CustomError (message, cause) {
Error.call(this)
if (Error.captureStackTrace)
- Error.captureStackTrace(this, arguments.callee)
+ Error.captureStackTrace(this, this.constructor)
init.call(this, 'CustomError', message, cause)
}
@@ -37,7 +39,7 @@ function createError (errno, type, proto) {
}
Error.call(this)
if (Error.captureStackTrace)
- Error.captureStackTrace(this, arguments.callee)
+ Error.captureStackTrace(this, err)
}
err.prototype = !!proto ? new proto() : new CustomError()
return err
diff --git a/node_modules/errno/package.json b/node_modules/errno/package.json
index aec4411fd..30ad0836c 100644
--- a/node_modules/errno/package.json
+++ b/node_modules/errno/package.json
@@ -9,7 +9,7 @@
"errno",
"libuv"
],
- "version": "0.1.5",
+ "version": "0.1.7",
"main": "errno.js",
"dependencies": {
"prr": "~1.0.1"
@@ -18,6 +18,8 @@
"errno": "./cli.js"
},
"devDependencies": {
+ "error-stack-parser": "^2.0.1",
+ "inherits": "^2.0.3",
"tape": "~4.8.0"
},
"repository": {
@@ -26,6 +28,6 @@
},
"license": "MIT",
"scripts": {
- "test": "tape test.js"
+ "test": "node --use_strict test.js"
}
}
diff --git a/node_modules/errno/test.js b/node_modules/errno/test.js
index 3a0ef7013..1c046357b 100755..100644
--- a/node_modules/errno/test.js
+++ b/node_modules/errno/test.js
@@ -1,7 +1,7 @@
-#!/usr/bin/env node
-
-var test = require('tape')
- , errno = require('./')
+var test = require('tape')
+ , inherits = require('inherits')
+ , ErrorStackParser = require('error-stack-parser')
+ , errno = require('./')
test('sanity checks', function (t) {
t.ok(errno.all, 'errno.all not found')
@@ -20,8 +20,8 @@ test('sanity checks', function (t) {
})
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')
t.equal(cust.name, 'FooNotBarError', 'correct custom name')
t.equal(cust.type, 'FooNotBarError', 'correct custom type')
@@ -29,3 +29,60 @@ test('custom errors', function (t) {
t.notOk(cust.cause, 'no cause')
t.end()
})
+
+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))
+ })
+})
+
+test('error without message', function (t) {
+ const Cust = errno.create('WriteError')
+ const cust = new Cust({
+ code: 22,
+ message: '',
+ name: 'QuotaExceededError'
+ })
+
+ t.equal(cust.name, 'WriteError', 'correct custom name')
+ t.equal(cust.type, 'WriteError', 'correct custom type')
+ t.equal(cust.message, 'QuotaExceededError', 'message is the name')
+ t.notOk(cust.cause, 'no cause')
+ t.end()
+})