Comparing version 5.2.0 to 6.0.0-npm-experiment1
@@ -5,4 +5,4 @@ 'use strict'; | ||
function IOError(originalError, prefix) { | ||
var err = new Error(prefix + ': ' + originalError.message); | ||
function IOError(cause, prefix) { | ||
var err = new Error(prefix + ': ' + cause.message); | ||
@@ -16,4 +16,4 @@ Object.defineProperty(err, 'type', { | ||
err.statusCode = 500; | ||
Object.defineProperty(err, 'original', { | ||
value: originalError, | ||
Object.defineProperty(err, 'cause', { | ||
value: cause, | ||
configurable: true, | ||
@@ -20,0 +20,0 @@ enumerable: false |
{ | ||
"name": "error", | ||
"version": "5.2.0", | ||
"version": "6.0.0-npm-experiment1", | ||
"description": "Custom errors", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var ServerListenError = WrappedError({ | ||
message: 'server: {origMessage}', | ||
message: 'server: {causeMessage}', | ||
type: 'server.listen-failed', | ||
@@ -30,3 +30,3 @@ requestedPort: null, | ||
assert.equal(err2.original, err); | ||
assert.equal(err2.cause, err); | ||
@@ -42,4 +42,6 @@ assert.equal(err2.toString(), | ||
name: 'ServerListenFailedError', | ||
causeMessage: 'listen EADDRINUSE', | ||
origMessage: 'listen EADDRINUSE', | ||
code: 'EADDRINUSE' | ||
code: 'EADDRINUSE', | ||
fullType: 'server.listen-failed~!~error.wrapped-unknown' | ||
})); | ||
@@ -52,3 +54,3 @@ | ||
var ServerListenError = WrappedError({ | ||
message: 'server: {origMessage}', | ||
message: 'server: {causeMessage}', | ||
type: 'server.listen-failed', | ||
@@ -71,4 +73,4 @@ requestedPort: null, | ||
function onError(originalError) { | ||
var err = ServerListenError(originalError, { | ||
function onError(cause) { | ||
var err = ServerListenError(cause, { | ||
host: 'localhost', | ||
@@ -79,7 +81,7 @@ requestedPort: port | ||
otherServer.close(); | ||
assertOnError(err, originalError, port); | ||
assertOnError(err, cause, port); | ||
} | ||
} | ||
function assertOnError(err, originalError, port) { | ||
function assertOnError(err, cause, port) { | ||
assert.equal(err.message, 'server: listen EADDRINUSE'); | ||
@@ -90,3 +92,3 @@ assert.equal(err.requestedPort, port); | ||
assert.equal(err.original, originalError); | ||
assert.equal(err.cause, cause); | ||
@@ -102,6 +104,9 @@ assert.equal(err.toString(), | ||
name: 'ServerListenFailedError', | ||
causeMessage: 'listen EADDRINUSE', | ||
origMessage: 'listen EADDRINUSE', | ||
code: 'EADDRINUSE', | ||
errno: 'EADDRINUSE', | ||
syscall: 'listen' | ||
syscall: 'listen', | ||
fullType: 'server.listen-failed~!~' + | ||
'error.wrapped-io.listen.EADDRINUSE' | ||
})); | ||
@@ -108,0 +113,0 @@ |
@@ -16,4 +16,8 @@ 'use strict'; | ||
assert(!has(options, 'original'), | ||
'WrappedError: original field is reserved'); | ||
assert(!has(options, 'cause'), | ||
'WrappedError: cause field is reserved'); | ||
assert(!has(options, 'fullType'), | ||
'WrappedError: fullType field is reserved'); | ||
assert(!has(options, 'causeMessage'), | ||
'WrappedError: causeMessage field is reserved'); | ||
assert(!has(options, 'origMessage'), | ||
@@ -26,25 +30,31 @@ 'WrappedError: origMessage field is reserved'); | ||
function createError(originalError, opts) { | ||
assert(originalError, 'an error is required'); | ||
assert(isError(originalError), | ||
function createError(cause, opts) { | ||
/*eslint max-statements: [2, 25]*/ | ||
assert(cause, 'an error is required'); | ||
assert(isError(cause), | ||
'WrappedError: first argument must be an error'); | ||
var err = createTypedError(extend(opts, { | ||
origMessage: originalError.message | ||
causeMessage: cause.message, | ||
origMessage: cause.message | ||
})); | ||
if (has(originalError, 'code') && !has(err, 'code')) { | ||
err.code = originalError.code; | ||
var nodeCause = false; | ||
if (has(cause, 'code') && !has(err, 'code')) { | ||
err.code = cause.code; | ||
} | ||
if (has(originalError, 'errno') && !has(err, 'errno')) { | ||
err.errno = originalError.errno; | ||
if (has(cause, 'errno') && !has(err, 'errno')) { | ||
err.errno = cause.errno; | ||
nodeCause = true; | ||
} | ||
if (has(originalError, 'syscall') && !has(err, 'syscall')) { | ||
err.syscall = originalError.syscall; | ||
if (has(cause, 'syscall') && !has(err, 'syscall')) { | ||
err.syscall = cause.syscall; | ||
nodeCause = true; | ||
} | ||
Object.defineProperty(err, 'original', { | ||
value: originalError, | ||
Object.defineProperty(err, 'cause', { | ||
value: cause, | ||
configurable: true, | ||
@@ -54,2 +64,14 @@ enumerable: false | ||
var causeType = err.cause.type; | ||
if (!causeType && nodeCause) { | ||
causeType = 'error.wrapped-io.' + | ||
(err.syscall || 'unknown') + '.' + | ||
(err.errno || 'unknown'); | ||
} else { | ||
causeType = 'error.wrapped-unknown'; | ||
} | ||
err.fullType = err.type + '~!~' + | ||
(err.cause.type || causeType); | ||
return err; | ||
@@ -56,0 +78,0 @@ } |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13829
266
1
1