errlop
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,2 +5,4 @@ '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); } } | ||
@@ -14,3 +16,3 @@ | ||
var util = require('util'); | ||
var isValidArray = ['undefined']; | ||
@@ -30,2 +32,15 @@ /** | ||
/** | ||
* 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)) | ||
* // "undefined" true false false undefined string [undefined] 0 | ||
* @param {*} value | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function isValid(value) { | ||
return Boolean(value) && isValidArray.indexOf(typeof value === 'undefined' ? 'undefined' : _typeof(value)) === -1; | ||
} | ||
/** | ||
* Create an instance of an error, using a message, as well as an optional parent. | ||
@@ -67,3 +82,3 @@ * If the parent is provided, then the `fullStack` property will include its stack too | ||
var ancestor = _this.parent; | ||
while (ancestor) { | ||
while (isValid(ancestor)) { | ||
_this.ancestors.push(ancestor); | ||
@@ -73,2 +88,11 @@ 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); | ||
} | ||
} | ||
/** | ||
@@ -80,7 +104,3 @@ * A numeric code to use for the exit status if desired by the consumer. | ||
*/ | ||
_this.exitCode = [input, _this].concat(_toConsumableArray(_this.ancestors)).map(function (error) { | ||
return parseCode(error.exitCode) || parseCode(error.errno) || parseCode(error.code); | ||
}).find(function (exitCode) { | ||
return exitCode != null; | ||
}); | ||
_this.exitCode = exitCode; | ||
@@ -87,0 +107,0 @@ /** |
# History | ||
## v1.0.1 2018 July 27 | ||
- Support node version 0.8 | ||
- Prevent a crash on node version 4 under special conditions | ||
## v1.0.0 2018 July 21 | ||
- Initial working release |
{ | ||
"name": "errlop", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An extended Error class that envelops a parent error, such that the stack trace contains the causation", | ||
@@ -29,5 +29,3 @@ "homepage": "https://github.com/bevry/errlop", | ||
"bitcoin", | ||
"wishlist", | ||
"---", | ||
"slackin" | ||
"wishlist" | ||
], | ||
@@ -40,4 +38,3 @@ "config": { | ||
"bitcoinURL": "https://bevry.me/bitcoin", | ||
"wishlistURL": "https://bevry.me/wishlist", | ||
"slackinURL": "https://slack.bevry.me" | ||
"wishlistURL": "https://bevry.me/wishlist" | ||
} | ||
@@ -54,3 +51,3 @@ }, | ||
"engines": { | ||
"node": ">=0.12" | ||
"node": ">=0.8" | ||
}, | ||
@@ -57,0 +54,0 @@ "editions": [ |
@@ -22,4 +22,2 @@ <!-- TITLE/ --> | ||
<span class="badge-wishlist"><a href="https://bevry.me/wishlist" title="Buy an item on our wishlist for us"><img src="https://img.shields.io/badge/wishlist-donate-yellow.svg" alt="Wishlist browse button" /></a></span> | ||
<br class="badge-separator" /> | ||
<span class="badge-slackin"><a href="https://slack.bevry.me" title="Join this project's slack community"><img src="https://slack.bevry.me/badge.svg" alt="Slack community badge" /></a></span> | ||
@@ -47,3 +45,3 @@ <!-- /BADGES --> | ||
<li>Module: <code>require('errlop')</code></li> | ||
<li>CDN URL: <code>//wzrd.in/bundle/errlop@1.0.0</code></li></ul> | ||
<li>CDN URL: <code>//wzrd.in/bundle/errlop@1.0.1</code></li></ul> | ||
@@ -167,3 +165,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> | ||
@@ -170,0 +168,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> |
'use strict' | ||
const util = require('util') | ||
const isValidArray = ['undefined'] | ||
@@ -18,2 +18,15 @@ /** | ||
/** | ||
* 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)) | ||
* // "undefined" true false false undefined string [undefined] 0 | ||
* @param {*} value | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function isValid (value) { | ||
return Boolean(value) && isValidArray.indexOf(typeof value) === -1 | ||
} | ||
/** | ||
* Create an instance of an error, using a message, as well as an optional parent. | ||
@@ -49,3 +62,3 @@ * If the parent is provided, then the `fullStack` property will include its stack too | ||
let ancestor = this.parent | ||
while (ancestor) { | ||
while (isValid(ancestor)) { | ||
this.ancestors.push(ancestor) | ||
@@ -55,2 +68,11 @@ 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) | ||
} | ||
} | ||
/** | ||
@@ -62,3 +84,3 @@ * A numeric code to use for the exit status if desired by the consumer. | ||
*/ | ||
this.exitCode = [input, this, ...this.ancestors].map((error) => parseCode(error.exitCode) || parseCode(error.errno) || parseCode(error.code)).find((exitCode) => exitCode != null) | ||
this.exitCode = exitCode | ||
@@ -65,0 +87,0 @@ /** |
25744
243
183