Comparing version 6.0.0 to 6.1.0
{ | ||
"name": "error", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Custom errors", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -49,2 +49,24 @@ 'use strict'; | ||
test('can create wrapped error with syscall', function t(assert) { | ||
var SysCallError = WrappedError({ | ||
'message': 'tchannel socket error ({code} from ' + | ||
'{syscall}): {origMessage}', | ||
type: 'syscall.error' | ||
}); | ||
var err = new Error('listen EADDRINUSE'); | ||
err.code = 'EADDRINUSE'; | ||
err.syscall = 'listen'; | ||
var err2 = SysCallError(err); | ||
assert.equal(err2.message, 'tchannel socket error ' + | ||
'(EADDRINUSE from listen): listen EADDRINUSE'); | ||
assert.equal(err2.syscall, 'listen'); | ||
assert.equal(err2.code, 'EADDRINUSE'); | ||
assert.equal(err2.type, 'syscall.error'); | ||
assert.end(); | ||
}); | ||
test('can wrap real IO errors', function t(assert) { | ||
@@ -51,0 +73,0 @@ var ServerListenError = WrappedError({ |
@@ -35,34 +35,27 @@ 'use strict'; | ||
var err = createTypedError(extend(opts, { | ||
var nodeCause = false; | ||
var errOptions = extend(opts, { | ||
causeMessage: cause.message, | ||
origMessage: cause.message | ||
})); | ||
}); | ||
var nodeCause = false; | ||
if (has(cause, 'code') && !has(err, 'code')) { | ||
err.code = cause.code; | ||
if (has(cause, 'code') && !has(errOptions, 'code')) { | ||
errOptions.code = cause.code; | ||
} | ||
if (has(cause, 'errno') && !has(err, 'errno')) { | ||
err.errno = cause.errno; | ||
if (has(cause, 'errno') && !has(errOptions, 'errno')) { | ||
errOptions.errno = cause.errno; | ||
nodeCause = true; | ||
} | ||
if (has(cause, 'syscall') && !has(err, 'syscall')) { | ||
err.syscall = cause.syscall; | ||
if (has(cause, 'syscall') && !has(errOptions, 'syscall')) { | ||
errOptions.syscall = cause.syscall; | ||
nodeCause = true; | ||
} | ||
Object.defineProperty(err, 'cause', { | ||
value: cause, | ||
configurable: true, | ||
enumerable: false | ||
}); | ||
var causeType = err.cause.type; | ||
var causeType = cause.type; | ||
if (!causeType && nodeCause) { | ||
causeType = 'error.wrapped-io.' + | ||
(err.syscall || 'unknown') + '.' + | ||
(err.errno || 'unknown'); | ||
(cause.syscall || 'unknown') + '.' + | ||
(cause.errno || 'unknown'); | ||
} else { | ||
@@ -72,5 +65,12 @@ causeType = 'error.wrapped-unknown'; | ||
err.fullType = err.type + '~!~' + | ||
(err.cause.type || causeType); | ||
errOptions.fullType = options.type + '~!~' + | ||
(cause.type || causeType); | ||
var err = createTypedError(errOptions); | ||
Object.defineProperty(err, 'cause', { | ||
value: cause, | ||
configurable: true, | ||
enumerable: false | ||
}); | ||
return err; | ||
@@ -77,0 +77,0 @@ } |
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
14451
284