Comparing version 1.0.2 to 1.0.3
@@ -12,4 +12,2 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
@@ -30,6 +28,13 @@ | ||
/** | ||
* Prevent [a weird error on node version 4](https://travis-ci.org/bevry/editions/jobs/408828147) which has the following properties | ||
* @example | ||
* console.log(JSON.stringify(typeof value), Boolean(value), typeof value === 'undefined', value == undefined, typeof value, typeof (typeof value), `[${typeof value}]`, ['undefined'].indexOf(typeof value), typeof (typeof value)) | ||
* // "undefined" true false false undefined string [undefined] 0 string | ||
* Fetch the code from the value | ||
* @param {Object|Error} value | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function fetchCode(value) { | ||
return value && (parseCode(value.exitCode) || parseCode(value.errno) || parseCode(value.code)); | ||
} | ||
/** | ||
* Prevent [a weird error on node version 4](https://github.com/bevry/errlop/issues/1) and below. | ||
* @param {*} value | ||
@@ -40,3 +45,4 @@ * @returns {boolean} | ||
function isValid(value) { | ||
return Boolean(value) && String(typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'undefined'; | ||
/* eslint no-use-before-define:0 */ | ||
return value instanceof Error || Errlop.isErrlop(value); | ||
} | ||
@@ -65,2 +71,11 @@ | ||
/** | ||
* Duck typing as node 4 and intanceof does not work for error extensions | ||
* @type {Errlop} | ||
* @public | ||
*/ | ||
var _this = _possibleConstructorReturn(this, (Errlop.__proto__ || Object.getPrototypeOf(Errlop)).call(this, input.message || input)); | ||
_this.klass = Errlop; | ||
/** | ||
* The parent error if it was provided. | ||
@@ -71,4 +86,2 @@ * If a parent was provided, then use that, otherwise use the input's parent, if it exists. | ||
*/ | ||
var _this = _possibleConstructorReturn(this, (Errlop.__proto__ || Object.getPrototypeOf(Errlop)).call(this, input.message || input)); | ||
_this.parent = parent || input.parent; | ||
@@ -83,3 +96,3 @@ | ||
var ancestor = _this.parent; | ||
while (isValid(ancestor)) { | ||
while (ancestor) { | ||
_this.ancestors.push(ancestor); | ||
@@ -90,8 +103,7 @@ ancestor = ancestor.parent; | ||
// this code must support node 0.8, as well as prevent a weird bug in node v4: https://travis-ci.org/bevry/editions/jobs/408828147 | ||
var exitCode = null; | ||
for (var index = 0, errors = [input, _this].concat(_toConsumableArray(_this.ancestors)); index < errors.length && exitCode == null; ++index) { | ||
var error = errors[index]; | ||
if (isValid(error)) { | ||
exitCode = parseCode(error.exitCode) || parseCode(error.errno) || parseCode(error.code); | ||
} | ||
var exitCode = fetchCode(input); | ||
if (exitCode == null) exitCode = fetchCode(_this); | ||
for (var index = 0; index < _this.ancestors.length && exitCode == null; ++index) { | ||
var error = _this.ancestors[index]; | ||
if (isValid(error)) exitCode = fetchCode(error); | ||
} | ||
@@ -148,4 +160,18 @@ | ||
/** | ||
* Ensure that the input value is an Errlop instance | ||
* Check whether or not the value is an Errlop instance | ||
* @param {*} value | ||
* @returns {boolean} | ||
* @static | ||
* @public | ||
*/ | ||
}, { | ||
key: 'isErrlop', | ||
value: function isErrlop(value) { | ||
return value && (value instanceof this || value.klass === this); | ||
} | ||
/** | ||
* Ensure that the value is an Errlop instance | ||
* @param {*} value | ||
* @returns {Errlop} | ||
@@ -159,3 +185,3 @@ * @static | ||
value: function ensure(value) { | ||
return value instanceof this ? value : this.create(value); | ||
return this.isErrlop(value) ? value : this.create(value); | ||
} | ||
@@ -162,0 +188,0 @@ }]); |
# History | ||
## v1.0.3 2018 August 19 | ||
- Add duck typing for node version 4 and under | ||
- Prevent additional crashes on node version 4 | ||
## v1.0.2 2018 July 27 | ||
@@ -8,5 +12,5 @@ - More effecient node version 4 crash prevention | ||
- Support node version 0.8 | ||
- Prevent a crash on node version 4 under special conditions | ||
- Prevent a peculiar crash on node version 4 | ||
## v1.0.0 2018 July 21 | ||
- Initial working release |
{ | ||
"name": "errlop", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "An extended Error class that envelops a parent error, such that the stack trace contains the causation", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/bevry/errlop", |
@@ -44,3 +44,3 @@ <!-- TITLE/ --> | ||
<li>Module: <code>require('errlop')</code></li> | ||
<li>CDN URL: <code>//wzrd.in/bundle/errlop@1.0.2</code></li></ul> | ||
<li>CDN URL: <code>//wzrd.in/bundle/errlop@1.0.3</code></li></ul> | ||
@@ -164,3 +164,3 @@ <a href="http://enderjs.com" title="Ender is a full featured package manager for your browser"><h3>Ender</h3></a><ul> | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a></li></ul> | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a> — <a href="https://github.com/bevry/errlop/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/errlop">view contributions</a></li></ul> | ||
@@ -167,0 +167,0 @@ <a href="https://github.com/bevry/errlop/blob/master/CONTRIBUTING.md#files">Discover how you can contribute by heading on over to the <code>CONTRIBUTING.md</code> file.</a> |
@@ -16,6 +16,15 @@ 'use strict' | ||
/** | ||
* Prevent [a weird error on node version 4](https://travis-ci.org/bevry/editions/jobs/408828147) which has the following properties | ||
* @example | ||
* console.log(JSON.stringify(typeof value), Boolean(value), typeof value === 'undefined', value == undefined, typeof value, typeof (typeof value), `[${typeof value}]`, ['undefined'].indexOf(typeof value), typeof (typeof value)) | ||
* // "undefined" true false false undefined string [undefined] 0 string | ||
* Fetch the code from the value | ||
* @param {Object|Error} value | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function fetchCode (value) { | ||
return value && ( | ||
parseCode(value.exitCode) || parseCode(value.errno) || parseCode(value.code) | ||
) | ||
} | ||
/** | ||
* Prevent [a weird error on node version 4](https://github.com/bevry/errlop/issues/1) and below. | ||
* @param {*} value | ||
@@ -26,3 +35,4 @@ * @returns {boolean} | ||
function isValid (value) { | ||
return Boolean(value) && String(typeof value) !== 'undefined' | ||
/* eslint no-use-before-define:0 */ | ||
return value instanceof Error || Errlop.isErrlop(value) | ||
} | ||
@@ -47,2 +57,9 @@ | ||
/** | ||
* Duck typing as node 4 and intanceof does not work for error extensions | ||
* @type {Errlop} | ||
* @public | ||
*/ | ||
this.klass = Errlop | ||
/** | ||
* The parent error if it was provided. | ||
@@ -62,3 +79,3 @@ * If a parent was provided, then use that, otherwise use the input's parent, if it exists. | ||
let ancestor = this.parent | ||
while (isValid(ancestor)) { | ||
while (ancestor) { | ||
this.ancestors.push(ancestor) | ||
@@ -69,8 +86,7 @@ ancestor = ancestor.parent | ||
// this code must support node 0.8, as well as prevent a weird bug in node v4: https://travis-ci.org/bevry/editions/jobs/408828147 | ||
let exitCode = null | ||
for (let index = 0, errors = [input, this, ...this.ancestors]; index < errors.length && exitCode == null; ++index) { | ||
const error = errors[index] | ||
if (isValid(error)) { | ||
exitCode = parseCode(error.exitCode) || parseCode(error.errno) || parseCode(error.code) | ||
} | ||
let exitCode = fetchCode(input) | ||
if (exitCode == null) exitCode = fetchCode(this) | ||
for (let index = 0; index < this.ancestors.length && exitCode == null; ++index) { | ||
const error = this.ancestors[index] | ||
if (isValid(error)) exitCode = fetchCode(error) | ||
} | ||
@@ -116,4 +132,15 @@ | ||
/** | ||
* Ensure that the input value is an Errlop instance | ||
* Check whether or not the value is an Errlop instance | ||
* @param {*} value | ||
* @returns {boolean} | ||
* @static | ||
* @public | ||
*/ | ||
static isErrlop (value) { | ||
return value && (value instanceof this || value.klass === this) | ||
} | ||
/** | ||
* Ensure that the value is an Errlop instance | ||
* @param {*} value | ||
* @returns {Errlop} | ||
@@ -124,3 +151,3 @@ * @static | ||
static ensure (value) { | ||
return (value instanceof this) ? value : this.create(value) | ||
return this.isErrlop(value) ? value : this.create(value) | ||
} | ||
@@ -127,0 +154,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
26094
288