Comparing version 1.0.0 to 1.0.1
@@ -14,2 +14,4 @@ List of changes | ||
4. Methods `batch` and `page` contain data as `data`, not directly. | ||
--- | ||
@@ -29,1 +31,2 @@ | ||
@@ -72,3 +72,2 @@ 'use strict'; | ||
} | ||
} | ||
@@ -75,0 +74,0 @@ |
'use strict'; | ||
var $npm = { | ||
u: require('util'), | ||
os: require('os'), | ||
@@ -8,2 +9,11 @@ utils: require('../utils/static') | ||
var errorReasons = { | ||
0: "Page with index %d failed to resolve.", | ||
1: "Source %s returned a rejection at index %d.", | ||
2: "Source %s threw an error at index %d.", | ||
3: "Destination %s returned a rejection at index %d.", | ||
4: "Destination %s threw an error at index %d.", | ||
5: "Source %s returned a non-array value at index %d." | ||
}; | ||
/** | ||
@@ -24,2 +34,6 @@ * @interface errors.PageError | ||
* | ||
* @property {number} index | ||
* | ||
* @property {} error | ||
* | ||
* @property {} source | ||
@@ -31,4 +45,6 @@ * | ||
* | ||
* @property {string} reason | ||
* | ||
*/ | ||
function PageError(e) { | ||
function PageError(e, code, cbName, duration) { | ||
@@ -39,2 +55,3 @@ var temp = Error.apply(this, arguments); | ||
this.index = e.index; | ||
this.duration = duration; | ||
@@ -57,5 +74,13 @@ if ('data' in e) { | ||
} | ||
if ('dest' in e) { | ||
this.dest = e.dest; | ||
} | ||
if (code) { | ||
cbName = cbName ? ("'" + cbName + "'") : '<anonymous>'; | ||
this.reason = $npm.u.format(errorReasons[code], cbName, e.index); | ||
} else { | ||
this.reason = $npm.u.format(errorReasons[code], e.index); | ||
} | ||
} | ||
@@ -89,5 +114,19 @@ | ||
'PageError {', | ||
gap1 + 'message: "' + this.message + '"' | ||
gap1 + 'message: ' + JSON.stringify(this.message), | ||
gap1 + 'reason: ' + this.reason, | ||
gap1 + 'index: ' + this.index | ||
]; | ||
if ('source' in this) { | ||
lines.push(gap1 + 'source: ' + $npm.u.inspect(this.source)); | ||
} | ||
if ('dest' in this) { | ||
lines.push(gap1 + 'dest: ' + $npm.u.inspect(this.dest)); | ||
} | ||
lines.push(gap1 + 'duration: ' + $npm.u.inspect(this.duration)); | ||
lines.push(gap1 + 'error: ' + $npm.u.inspect(this.error)); | ||
lines.push(gap0 + '}'); | ||
return lines.join($npm.os.EOL); | ||
@@ -94,0 +133,0 @@ }; |
@@ -9,7 +9,7 @@ 'use strict'; | ||
var errDetails = { | ||
0: "Source function '%s' returned a rejected promise.", | ||
1: "Source function '%s' threw an error.", | ||
2: "Destination function '%s' returned a rejected promise.", | ||
3: "Destination function '%s' threw an error." | ||
var errorReasons = { | ||
0: "Source %s returned a rejection at index %d.", | ||
1: "Source %s threw an error at index %d.", | ||
2: "Destination %s returned a rejection at index %d.", | ||
3: "Destination %s threw an error at index %d." | ||
}; | ||
@@ -32,18 +32,37 @@ | ||
* | ||
* @property {number} index | ||
* | ||
* @property {} source | ||
* | ||
* @property {} dest | ||
* | ||
* @property {} duration | ||
* | ||
* @property {string} reason | ||
* | ||
*/ | ||
function SequenceError(e, code, cbName, duration) { | ||
var temp = Error.apply(this, arguments); | ||
temp.name = this.name = 'SequenceError'; | ||
this.error = e.error; | ||
this.message = e.error.message || e.error; | ||
this.index = e.index; | ||
this.duration = duration; | ||
this.error = e.error; | ||
if (this.error instanceof Error) { | ||
this.message = this.error.message; | ||
} else { | ||
this.message = this.error; | ||
} | ||
if ('source' in e) { | ||
this.source = e.source; | ||
} | ||
if ('dest' in e) { | ||
} else { | ||
this.dest = e.dest; | ||
} | ||
this.reason = $npm.u.format(errDetails[code], cbName || '<anonymous>'); | ||
cbName = cbName ? ("'" + cbName + "'") : '<anonymous>'; | ||
this.reason = $npm.u.format(errorReasons[code], cbName, e.index); | ||
} | ||
@@ -50,0 +69,0 @@ |
@@ -75,3 +75,3 @@ 'use strict'; | ||
if (!Array.isArray(values)) { | ||
return $p.reject(new TypeError("Batch requires an array of values.")); | ||
return $p.reject(new TypeError("Method 'batch' requires an array of values.")); | ||
} | ||
@@ -147,3 +147,5 @@ | ||
} | ||
reject(new BatchError(result, errors, Date.now() - start)); | ||
var e = new BatchError(result, errors, Date.now() - start); | ||
reject(e); | ||
Object.freeze(e); | ||
} else { | ||
@@ -150,0 +152,0 @@ $utils.extend(result, 'duration', Date.now() - start); |
@@ -99,3 +99,3 @@ 'use strict'; | ||
if (typeof source !== 'function') { | ||
return $p.reject(new TypeError("Invalid page source.")); | ||
return $p.reject(new TypeError("Parameter 'source' must be a function.")); | ||
} | ||
@@ -134,3 +134,3 @@ | ||
dest: data | ||
}); | ||
}, 4, dest.name); | ||
return; | ||
@@ -145,3 +145,3 @@ } | ||
dest: data | ||
}); | ||
}, 3, dest.name); | ||
}); | ||
@@ -159,3 +159,3 @@ } else { | ||
data: error | ||
}); | ||
}, 0); | ||
}); | ||
@@ -166,12 +166,12 @@ } else { | ||
source: request | ||
}); | ||
}, 5, source.name); | ||
} | ||
} | ||
}, function (reason) { | ||
}, function (reason, isRej) { | ||
fail({ | ||
error: reason, | ||
source: request | ||
}); | ||
}, isRej ? 1 : 2, source.name); | ||
}); | ||
function next() { | ||
@@ -193,6 +193,8 @@ if (limit === ++idx) { | ||
} | ||
function fail(reason) { | ||
function fail(reason, code, cbName) { | ||
reason.index = idx; | ||
reject(new PageError(reason)); | ||
var error = new PageError(reason, code, cbName, Date.now() - start); | ||
reject(error); | ||
Object.freeze(error); | ||
} | ||
@@ -199,0 +201,0 @@ } |
@@ -93,3 +93,3 @@ 'use strict'; | ||
if (typeof source !== 'function') { | ||
return $p.reject(new TypeError("Invalid sequence source.")); | ||
return $p.reject(new TypeError("Parameter 'source' must be a function.")); | ||
} | ||
@@ -112,3 +112,3 @@ | ||
if (data === undefined) { | ||
finish(); | ||
success(); | ||
} else { | ||
@@ -125,7 +125,6 @@ if (track) { | ||
} catch (e) { | ||
reject(new SequenceError({ | ||
index: idx, | ||
fail({ | ||
error: e, | ||
dest: data | ||
}, 3, dest.name, Date.now() - start)); | ||
}, 3, dest.name); | ||
return; | ||
@@ -140,7 +139,6 @@ } | ||
.catch(function (error) { | ||
reject(new SequenceError({ | ||
index: idx, | ||
fail({ | ||
error: error, | ||
dest: data | ||
}, 2, dest.name, Date.now() - start)); | ||
}, 2, dest.name); | ||
}); | ||
@@ -154,8 +152,7 @@ } else { | ||
} | ||
}, function (reason, rej) { | ||
reject(new SequenceError({ | ||
index: idx, | ||
}, function (reason, isRej) { | ||
fail({ | ||
error: reason, | ||
source: data | ||
}, rej ? 0 : 1, source.name, Date.now() - start)); | ||
}, isRej ? 0 : 1, source.name); | ||
}); | ||
@@ -165,3 +162,3 @@ | ||
if (limit === ++idx) { | ||
finish(); | ||
success(); | ||
} else { | ||
@@ -180,3 +177,3 @@ if (delayed) { | ||
function finish() { | ||
function success() { | ||
var length = Date.now() - start; | ||
@@ -193,2 +190,9 @@ if (track) { | ||
} | ||
function fail(reason, code, cbName) { | ||
reason.index = idx; | ||
var error = new SequenceError(reason, code, cbName, Date.now() - start); | ||
reject(error); | ||
Object.freeze(error); | ||
} | ||
} | ||
@@ -195,0 +199,0 @@ |
{ | ||
"name": "spex", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Specialized Promise Extensions", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
58722
1386