@blackglory/errors
Advanced tools
Comparing version 2.1.0 to 2.2.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iterable-operator'), require('@blackglory/types')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'iterable-operator', '@blackglory/types'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Errors = {}, global.iterableOperator, global.types)); | ||
})(this, (function (exports, iterableOperator, types) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iterable-operator'), require('@blackglory/types'), require('@blackglory/pass')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'iterable-operator', '@blackglory/types', '@blackglory/pass'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Errors = {}, global.iterableOperator, global.types, global.pass)); | ||
})(this, (function (exports, iterableOperator, types, pass) { 'use strict'; | ||
@@ -75,2 +75,26 @@ function* traverseErrorPrototypeChain(err) { | ||
function hydrate(err) { | ||
var _a; | ||
const errorNames = [err.name, ...err.ancestors] | ||
.slice(0, -1) | ||
.reverse(); | ||
let errorConstructor = Error; | ||
for (const name of errorNames) { | ||
errorConstructor = createChildErrorConstructor(errorConstructor, name); | ||
} | ||
const result = new errorConstructor(); | ||
result.name = err.name; | ||
result.message = err.message; | ||
result.stack = (_a = err.stack) !== null && _a !== void 0 ? _a : undefined; | ||
return result; | ||
} | ||
function createChildErrorConstructor(parentErrorConstructor, name) { | ||
const constructor = function () { pass.pass(); }; | ||
constructor.prototype = Object.create(parentErrorConstructor.prototype); | ||
constructor.prototype.constructor = constructor; | ||
// 函数的name属性是只读的, 所以必须这样修改 | ||
Object.defineProperty(constructor, 'name', { value: name }); | ||
return constructor; | ||
} | ||
/** | ||
@@ -88,2 +112,3 @@ * @throws {AssertionError} | ||
exports.getErrorNames = getErrorNames; | ||
exports.hydrate = hydrate; | ||
exports.isSerializableError = isSerializableError; | ||
@@ -90,0 +115,0 @@ exports.normalize = normalize; |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("iterable-operator"),require("@blackglory/types")):"function"==typeof define&&define.amd?define(["exports","iterable-operator","@blackglory/types"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Errors={},e.iterableOperator,e.types)}(this,(function(e,r,t){"use strict";function*o(e){let r=e;for(;(r=Object.getPrototypeOf(r))&&(yield r,r!==Error.prototype););}function*s(e){var r;if(t.isError(e))for(const t of o(e))(null===(r=t.constructor)||void 0===r?void 0:r.name)&&(yield t.constructor.name);else yield e.name,yield*e.ancestors}function n(e){return t.isObject(e)&&t.isString(e.name)&&t.isString(e.message)&&(t.isString(e.stack)||t.isNull(e.stack))&&t.isArray(e.ancestors)&&e.ancestors.every(t.isString)}class i extends Error{get name(){var e,t;return null!==(t=null!==(e=r.first(s(this)))&&void 0!==e?e:i.name)&&void 0!==t?t:"CustomError"}static[Symbol.hasInstance](e){var o;if(t.isError(e)||n(e)){const t=[null!==(o=this.prototype.constructor.name)&&void 0!==o?o:this.name,...s(this.prototype)].reverse(),n=r.toArray(s(e)).reverse();return t.every(((e,r)=>e===n[r]))}return!1}}class a extends i{}e.AssertionError=a,e.CustomError=i,e.assert=function(e,r){if(!e)throw new a(r)},e.getErrorNames=s,e.isSerializableError=n,e.normalize=function(e){var t;const[o,...n]=r.toArray(s(e));return{name:o,ancestors:n,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}},e.traverseErrorPrototypeChain=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("iterable-operator"),require("@blackglory/types"),require("@blackglory/pass")):"function"==typeof define&&define.amd?define(["exports","iterable-operator","@blackglory/types","@blackglory/pass"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Errors={},e.iterableOperator,e.types,e.pass)}(this,(function(e,r,t,o){"use strict";function*s(e){let r=e;for(;(r=Object.getPrototypeOf(r))&&(yield r,r!==Error.prototype););}function*n(e){var r;if(t.isError(e))for(const t of s(e))(null===(r=t.constructor)||void 0===r?void 0:r.name)&&(yield t.constructor.name);else yield e.name,yield*e.ancestors}function a(e){return t.isObject(e)&&t.isString(e.name)&&t.isString(e.message)&&(t.isString(e.stack)||t.isNull(e.stack))&&t.isArray(e.ancestors)&&e.ancestors.every(t.isString)}class i extends Error{get name(){var e,t;return null!==(t=null!==(e=r.first(n(this)))&&void 0!==e?e:i.name)&&void 0!==t?t:"CustomError"}static[Symbol.hasInstance](e){var o;if(t.isError(e)||a(e)){const t=[null!==(o=this.prototype.constructor.name)&&void 0!==o?o:this.name,...n(this.prototype)].reverse(),s=r.toArray(n(e)).reverse();return t.every(((e,r)=>e===s[r]))}return!1}}class c extends i{}function l(e,r){const t=function(){o.pass()};return(t.prototype=Object.create(e.prototype)).constructor=t,Object.defineProperty(t,"name",{value:r}),t}e.AssertionError=c,e.CustomError=i,e.assert=function(e,r){if(!e)throw new c(r)},e.getErrorNames=n,e.hydrate=function(e){var r;const t=[e.name,...e.ancestors].slice(0,-1).reverse();let o=Error;for(const e of t)o=l(o,e);const s=new o;return s.name=e.name,s.message=e.message,s.stack=null!==(r=e.stack)&&void 0!==r?r:void 0,s},e.isSerializableError=a,e.normalize=function(e){var t;const[o,...s]=r.toArray(n(e));return{name:o,ancestors:s,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}},e.traverseErrorPrototypeChain=s,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iterable-operator'), require('@blackglory/types')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'iterable-operator', '@blackglory/types'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Errors = {}, global.iterableOperator, global.types)); | ||
})(this, (function (exports, iterableOperator, types) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iterable-operator'), require('@blackglory/types'), require('@blackglory/pass')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'iterable-operator', '@blackglory/types', '@blackglory/pass'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Errors = {}, global.iterableOperator, global.types, global.pass)); | ||
})(this, (function (exports, iterableOperator, types, pass) { 'use strict'; | ||
@@ -75,2 +75,26 @@ function* traverseErrorPrototypeChain(err) { | ||
function hydrate(err) { | ||
var _a; | ||
const errorNames = [err.name, ...err.ancestors] | ||
.slice(0, -1) | ||
.reverse(); | ||
let errorConstructor = Error; | ||
for (const name of errorNames) { | ||
errorConstructor = createChildErrorConstructor(errorConstructor, name); | ||
} | ||
const result = new errorConstructor(); | ||
result.name = err.name; | ||
result.message = err.message; | ||
result.stack = (_a = err.stack) !== null && _a !== void 0 ? _a : undefined; | ||
return result; | ||
} | ||
function createChildErrorConstructor(parentErrorConstructor, name) { | ||
const constructor = function () { pass.pass(); }; | ||
constructor.prototype = Object.create(parentErrorConstructor.prototype); | ||
constructor.prototype.constructor = constructor; | ||
// 函数的name属性是只读的, 所以必须这样修改 | ||
Object.defineProperty(constructor, 'name', { value: name }); | ||
return constructor; | ||
} | ||
/** | ||
@@ -88,2 +112,3 @@ * @throws {AssertionError} | ||
exports.getErrorNames = getErrorNames; | ||
exports.hydrate = hydrate; | ||
exports.isSerializableError = isSerializableError; | ||
@@ -90,0 +115,0 @@ exports.normalize = normalize; |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("iterable-operator"),require("@blackglory/types")):"function"==typeof define&&define.amd?define(["exports","iterable-operator","@blackglory/types"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Errors={},e.iterableOperator,e.types)}(this,(function(e,r,t){"use strict";function*o(e){let r=e;for(;(r=Object.getPrototypeOf(r))&&(yield r,r!==Error.prototype););}function*s(e){var r;if(t.isError(e))for(const t of o(e))(null===(r=t.constructor)||void 0===r?void 0:r.name)&&(yield t.constructor.name);else yield e.name,yield*e.ancestors}function n(e){return t.isObject(e)&&t.isString(e.name)&&t.isString(e.message)&&(t.isString(e.stack)||t.isNull(e.stack))&&t.isArray(e.ancestors)&&e.ancestors.every(t.isString)}class i extends Error{get name(){var e,t;return null!==(t=null!==(e=r.first(s(this)))&&void 0!==e?e:i.name)&&void 0!==t?t:"CustomError"}static[Symbol.hasInstance](e){var o;if(t.isError(e)||n(e)){const t=[null!==(o=this.prototype.constructor.name)&&void 0!==o?o:this.name,...s(this.prototype)].reverse(),n=r.toArray(s(e)).reverse();return t.every(((e,r)=>e===n[r]))}return!1}}class a extends i{}e.AssertionError=a,e.CustomError=i,e.assert=function(e,r){if(!e)throw new a(r)},e.getErrorNames=s,e.isSerializableError=n,e.normalize=function(e){var t;const[o,...n]=r.toArray(s(e));return{name:o,ancestors:n,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}},e.traverseErrorPrototypeChain=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("iterable-operator"),require("@blackglory/types"),require("@blackglory/pass")):"function"==typeof define&&define.amd?define(["exports","iterable-operator","@blackglory/types","@blackglory/pass"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).Errors={},e.iterableOperator,e.types,e.pass)}(this,(function(e,r,t,o){"use strict";function*s(e){let r=e;for(;(r=Object.getPrototypeOf(r))&&(yield r,r!==Error.prototype););}function*n(e){var r;if(t.isError(e))for(const t of s(e))(null===(r=t.constructor)||void 0===r?void 0:r.name)&&(yield t.constructor.name);else yield e.name,yield*e.ancestors}function a(e){return t.isObject(e)&&t.isString(e.name)&&t.isString(e.message)&&(t.isString(e.stack)||t.isNull(e.stack))&&t.isArray(e.ancestors)&&e.ancestors.every(t.isString)}class i extends Error{get name(){var e,t;return null!==(t=null!==(e=r.first(n(this)))&&void 0!==e?e:i.name)&&void 0!==t?t:"CustomError"}static[Symbol.hasInstance](e){var o;if(t.isError(e)||a(e)){const t=[null!==(o=this.prototype.constructor.name)&&void 0!==o?o:this.name,...n(this.prototype)].reverse(),s=r.toArray(n(e)).reverse();return t.every(((e,r)=>e===s[r]))}return!1}}class c extends i{}function l(e,r){const t=function(){o.pass()};return(t.prototype=Object.create(e.prototype)).constructor=t,Object.defineProperty(t,"name",{value:r}),t}e.AssertionError=c,e.CustomError=i,e.assert=function(e,r){if(!e)throw new c(r)},e.getErrorNames=n,e.hydrate=function(e){var r;const t=[e.name,...e.ancestors].slice(0,-1).reverse();let o=Error;for(const e of t)o=l(o,e);const s=new o;return s.name=e.name,s.message=e.message,s.stack=null!==(r=e.stack)&&void 0!==r?r:void 0,s},e.isSerializableError=a,e.normalize=function(e){var t;const[o,...s]=r.toArray(n(e));return{name:o,ancestors:s,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}},e.traverseErrorPrototypeChain=s,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -5,4 +5,5 @@ export * from './custom-error'; | ||
export * from './normalize'; | ||
export * from './hydrate'; | ||
export * from './assert'; | ||
export * from './get-error-names'; | ||
export * from './traverse-error-prototype-chain'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
__exportStar(require("./normalize"), exports); | ||
__exportStar(require("./hydrate"), exports); | ||
__exportStar(require("./assert"), exports); | ||
@@ -19,0 +20,0 @@ __exportStar(require("./get-error-names"), exports); |
@@ -5,4 +5,5 @@ export * from './custom-error'; | ||
export * from './normalize'; | ||
export * from './hydrate'; | ||
export * from './assert'; | ||
export * from './get-error-names'; | ||
export * from './traverse-error-prototype-chain'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
__exportStar(require("./normalize"), exports); | ||
__exportStar(require("./hydrate"), exports); | ||
__exportStar(require("./assert"), exports); | ||
@@ -19,0 +20,0 @@ __exportStar(require("./get-error-names"), exports); |
{ | ||
"name": "@blackglory/errors", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Common errors", | ||
@@ -49,11 +49,11 @@ "files": [ | ||
"@types/jest": "^27.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.10.1", | ||
"@typescript-eslint/parser": "^5.10.1", | ||
"eslint": "^8.7.0", | ||
"@typescript-eslint/eslint-plugin": "^5.11.0", | ||
"@typescript-eslint/parser": "^5.11.0", | ||
"eslint": "^8.8.0", | ||
"husky": "^4.3.8", | ||
"jest": "^27.4.7", | ||
"jest": "^27.5.1", | ||
"npm-run-all": "^4.1.5", | ||
"return-style": "^0.12.6", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.66.1", | ||
"rollup": "^2.67.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
@@ -68,4 +68,5 @@ "standard-version": "^9.3.2", | ||
"dependencies": { | ||
"@blackglory/pass": "^0.1.0", | ||
"iterable-operator": "^0.14.5" | ||
} | ||
} |
@@ -43,2 +43,7 @@ # errors | ||
### hydrate | ||
```ts | ||
function hydrate(err: SerializableError): Error | ||
``` | ||
### isSerializableError | ||
@@ -45,0 +50,0 @@ ```ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
106041
73
808
70
0
2
+ Added@blackglory/pass@^0.1.0
+ Added@blackglory/pass@0.1.0(transitive)