yerror 6.0.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# [6.1.0](https://github.com/nfroidure/yerror/compare/v6.0.2...v6.1.0) (2022-05-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **api:** export class as non-default for ESM compatibility ([355a929](https://github.com/nfroidure/yerror/commit/355a92922300e5e4730d30da6be35e84d8552585))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [6.0.2](https://github.com/nfroidure/yerror/compare/v6.0.1...v6.0.2) (2022-05-25)
|
|
2
11
|
|
|
3
12
|
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.YError = void 0;
|
|
7
7
|
|
|
8
8
|
var _os = _interopRequireDefault(require("os"));
|
|
9
9
|
|
|
@@ -100,6 +100,8 @@ let YError = /*#__PURE__*/function (_Error) {
|
|
|
100
100
|
*/
|
|
101
101
|
|
|
102
102
|
|
|
103
|
+
exports.YError = YError;
|
|
104
|
+
|
|
103
105
|
YError.wrap = function yerrorWrap(err, errorCode, ...params) {
|
|
104
106
|
let yError = null;
|
|
105
107
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["YError","wrappedErrors","errorCode","params","Array","concat","code","name","toString","Error","captureStackTrace","constructor","length","stack","os","EOL","join","wrap","yerrorWrap","err","yError","wrappedErrorIsACode","_looksLikeAYErrorCode","message","push","cast","yerrorCast","_looksLikeAYError","apply","bump","yerrorBump","endsWith","str","test"],"sources":["../src/index.js"],"sourcesContent":["import os from 'os';\n\n/**\n * An YError class able to contain some params and\n * print better stack traces\n * @extends Error\n */\nclass YError extends Error {\n /**\n * Creates a new YError with an error code\n * and some params as debug values.\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n */\n constructor(wrappedErrors, errorCode, ...params) {\n // Detecting if wrappedErrors are passed\n if (!(wrappedErrors instanceof Array)) {\n params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(\n params,\n );\n errorCode = wrappedErrors;\n wrappedErrors = [];\n }\n\n // Call the parent constructor\n super(errorCode);\n\n // Filling error\n this.code = errorCode || 'E_UNEXPECTED';\n this.params = params;\n this.wrappedErrors = wrappedErrors;\n this.name = this.toString();\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n toString() {\n return (\n (this.wrappedErrors.length\n ? // eslint-disable-next-line\n this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL\n : '') +\n this.constructor.name +\n ': ' +\n this.code +\n ' (' +\n this.params.join(', ') +\n ')'\n );\n }\n}\n\n/**\n * Wraps any error and output a YError with an error\n * code and some params as debug values.\n * @param {Error} err\n * The error to wrap\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.wrap = function yerrorWrap(err, errorCode, ...params) {\n let yError = null;\n const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);\n const wrappedErrors = (err.wrappedErrors || []).concat(err);\n\n if (!errorCode) {\n if (wrappedErrorIsACode) {\n errorCode = err.message;\n } else {\n errorCode = 'E_UNEXPECTED';\n }\n }\n if (err.message && !wrappedErrorIsACode) {\n params.push(err.message);\n }\n yError = new YError(wrappedErrors, errorCode, ...params);\n return yError;\n};\n\n/**\n * Return a YError as is or wraps any other error and output\n * a YError with a code and some params as debug values.\n * @param {Error} err\n * The error to cast\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.cast = function yerrorCast(err, ...params) {\n if (_looksLikeAYError(err)) {\n return err;\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n/**\n * Same than `YError.wrap()` but preserves the code\n * and the debug values of the error if it is\n * already an instance of the YError constructor.\n * @param {Error} err\n * The error to bump\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.bump = function yerrorBump(err, ...params) {\n if (_looksLikeAYError(err)) {\n return YError.wrap.apply(YError, [err, err.code].concat(err.params));\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n// In order to keep compatibility through major versions\n// we have to make kind of an cross major version instanceof\nfunction _looksLikeAYError(err) {\n return (\n err instanceof YError ||\n (err.constructor &&\n err.constructor.name &&\n err.constructor.name.endsWith('Error') &&\n 'string' === typeof err.code &&\n _looksLikeAYErrorCode(err.code) &&\n err.params &&\n err.params instanceof Array)\n );\n}\n\nfunction _looksLikeAYErrorCode(str) {\n return /^([A-Z0-9_]+)$/.test(str);\n}\n\nexport default YError;\n"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;IACMA,M;;;EACJ;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,gBAAYC,aAAZ,EAA2BC,SAA3B,EAAsC,GAAGC,MAAzC,EAAiD;IAAA;;IAAA;;IAC/C;IACA,IAAI,EAAEF,aAAa,YAAYG,KAA3B,CAAJ,EAAuC;MACrCD,MAAM,GAAG,CAAC,gBAAgB,OAAOD,SAAvB,GAAmC,EAAnC,GAAwC,CAACA,SAAD,CAAzC,EAAsDG,MAAtD,CACPF,MADO,CAAT;MAGAD,SAAS,GAAGD,aAAZ;MACAA,aAAa,GAAG,EAAhB;IACD,CAR8C,CAU/C;;;IACA,4EAAMC,SAAN,GAX+C,CAa/C;;IACA,MAAKI,IAAL,GAAYJ,SAAS,IAAI,cAAzB;IACA,MAAKC,MAAL,GAAcA,MAAd;IACA,MAAKF,aAAL,GAAqBA,aAArB;IACA,MAAKM,IAAL,GAAY,MAAKC,QAAL,EAAZ;;IAEA,IAAIC,KAAK,CAACC,iBAAV,EAA6B;MAC3BD,KAAK,CAACC,iBAAN,gCAA8B,MAAKC,WAAnC;IACD;;IArB8C;EAsBhD;;;;+BAEU;MACT,OACE,CAAC,KAAKV,aAAL,CAAmBW,MAAnB,GACG;MACA,KAAKX,aAAL,CAAmB,KAAKA,aAAL,CAAmBW,MAAnB,GAA4B,CAA/C,EAAkDC,KAAlD,GAA0DC,WAAA,CAAGC,GAFhE,GAGG,EAHJ,IAIA,KAAKJ,WAAL,CAAiBJ,IAJjB,GAKA,IALA,GAMA,KAAKD,IANL,GAOA,IAPA,GAQA,KAAKH,MAAL,CAAYa,IAAZ,CAAiB,IAAjB,CARA,GASA,GAVF;IAYD;;;;mBA9CkBP,K;AAiDrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"file":"index.js","names":["YError","wrappedErrors","errorCode","params","Array","concat","code","name","toString","Error","captureStackTrace","constructor","length","stack","os","EOL","join","wrap","yerrorWrap","err","yError","wrappedErrorIsACode","_looksLikeAYErrorCode","message","push","cast","yerrorCast","_looksLikeAYError","apply","bump","yerrorBump","endsWith","str","test"],"sources":["../src/index.js"],"sourcesContent":["import os from 'os';\n\n/**\n * An YError class able to contain some params and\n * print better stack traces\n * @extends Error\n */\nclass YError extends Error {\n /**\n * Creates a new YError with an error code\n * and some params as debug values.\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n */\n constructor(wrappedErrors, errorCode, ...params) {\n // Detecting if wrappedErrors are passed\n if (!(wrappedErrors instanceof Array)) {\n params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(\n params,\n );\n errorCode = wrappedErrors;\n wrappedErrors = [];\n }\n\n // Call the parent constructor\n super(errorCode);\n\n // Filling error\n this.code = errorCode || 'E_UNEXPECTED';\n this.params = params;\n this.wrappedErrors = wrappedErrors;\n this.name = this.toString();\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n toString() {\n return (\n (this.wrappedErrors.length\n ? // eslint-disable-next-line\n this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL\n : '') +\n this.constructor.name +\n ': ' +\n this.code +\n ' (' +\n this.params.join(', ') +\n ')'\n );\n }\n}\n\n/**\n * Wraps any error and output a YError with an error\n * code and some params as debug values.\n * @param {Error} err\n * The error to wrap\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.wrap = function yerrorWrap(err, errorCode, ...params) {\n let yError = null;\n const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);\n const wrappedErrors = (err.wrappedErrors || []).concat(err);\n\n if (!errorCode) {\n if (wrappedErrorIsACode) {\n errorCode = err.message;\n } else {\n errorCode = 'E_UNEXPECTED';\n }\n }\n if (err.message && !wrappedErrorIsACode) {\n params.push(err.message);\n }\n yError = new YError(wrappedErrors, errorCode, ...params);\n return yError;\n};\n\n/**\n * Return a YError as is or wraps any other error and output\n * a YError with a code and some params as debug values.\n * @param {Error} err\n * The error to cast\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.cast = function yerrorCast(err, ...params) {\n if (_looksLikeAYError(err)) {\n return err;\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n/**\n * Same than `YError.wrap()` but preserves the code\n * and the debug values of the error if it is\n * already an instance of the YError constructor.\n * @param {Error} err\n * The error to bump\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.bump = function yerrorBump(err, ...params) {\n if (_looksLikeAYError(err)) {\n return YError.wrap.apply(YError, [err, err.code].concat(err.params));\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n// In order to keep compatibility through major versions\n// we have to make kind of an cross major version instanceof\nfunction _looksLikeAYError(err) {\n return (\n err instanceof YError ||\n (err.constructor &&\n err.constructor.name &&\n err.constructor.name.endsWith('Error') &&\n 'string' === typeof err.code &&\n _looksLikeAYErrorCode(err.code) &&\n err.params &&\n err.params instanceof Array)\n );\n}\n\nfunction _looksLikeAYErrorCode(str) {\n return /^([A-Z0-9_]+)$/.test(str);\n}\n\nexport default YError;\nexport { YError };\n"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;IACMA,M;;;EACJ;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,gBAAYC,aAAZ,EAA2BC,SAA3B,EAAsC,GAAGC,MAAzC,EAAiD;IAAA;;IAAA;;IAC/C;IACA,IAAI,EAAEF,aAAa,YAAYG,KAA3B,CAAJ,EAAuC;MACrCD,MAAM,GAAG,CAAC,gBAAgB,OAAOD,SAAvB,GAAmC,EAAnC,GAAwC,CAACA,SAAD,CAAzC,EAAsDG,MAAtD,CACPF,MADO,CAAT;MAGAD,SAAS,GAAGD,aAAZ;MACAA,aAAa,GAAG,EAAhB;IACD,CAR8C,CAU/C;;;IACA,4EAAMC,SAAN,GAX+C,CAa/C;;IACA,MAAKI,IAAL,GAAYJ,SAAS,IAAI,cAAzB;IACA,MAAKC,MAAL,GAAcA,MAAd;IACA,MAAKF,aAAL,GA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H,GAAG,CAACb,IAAL,CAJtB,IAKCa,GAAG,CAAChB,MALL,IAMCgB,GAAG,CAAChB,MAAJ,YAAsBC,KAR1B;AAUD;;AAED,SAASkB,qBAAT,CAA+BU,GAA/B,EAAoC;EAClC,OAAO,iBAAiBC,IAAjB,CAAsBD,GAAtB,CAAP;AACD;;eAEchC,M"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["os","YError","wrappedErrors","errorCode","params","Array","concat","code","name","toString","Error","captureStackTrace","constructor","length","stack","EOL","join","wrap","yerrorWrap","err","yError","wrappedErrorIsACode","_looksLikeAYErrorCode","message","push","cast","yerrorCast","_looksLikeAYError","apply","bump","yerrorBump","endsWith","str","test"],"sources":["../src/index.js"],"sourcesContent":["import os from 'os';\n\n/**\n * An YError class able to contain some params and\n * print better stack traces\n * @extends Error\n */\nclass YError extends Error {\n /**\n * Creates a new YError with an error code\n * and some params as debug values.\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n */\n constructor(wrappedErrors, errorCode, ...params) {\n // Detecting if wrappedErrors are passed\n if (!(wrappedErrors instanceof Array)) {\n params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(\n params,\n );\n errorCode = wrappedErrors;\n wrappedErrors = [];\n }\n\n // Call the parent constructor\n super(errorCode);\n\n // Filling error\n this.code = errorCode || 'E_UNEXPECTED';\n this.params = params;\n this.wrappedErrors = wrappedErrors;\n this.name = this.toString();\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n toString() {\n return (\n (this.wrappedErrors.length\n ? // eslint-disable-next-line\n this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL\n : '') +\n this.constructor.name +\n ': ' +\n this.code +\n ' (' +\n this.params.join(', ') +\n ')'\n );\n }\n}\n\n/**\n * Wraps any error and output a YError with an error\n * code and some params as debug values.\n * @param {Error} err\n * The error to wrap\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.wrap = function yerrorWrap(err, errorCode, ...params) {\n let yError = null;\n const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);\n const wrappedErrors = (err.wrappedErrors || []).concat(err);\n\n if (!errorCode) {\n if (wrappedErrorIsACode) {\n errorCode = err.message;\n } else {\n errorCode = 'E_UNEXPECTED';\n }\n }\n if (err.message && !wrappedErrorIsACode) {\n params.push(err.message);\n }\n yError = new YError(wrappedErrors, errorCode, ...params);\n return yError;\n};\n\n/**\n * Return a YError as is or wraps any other error and output\n * a YError with a code and some params as debug values.\n * @param {Error} err\n * The error to cast\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.cast = function yerrorCast(err, ...params) {\n if (_looksLikeAYError(err)) {\n return err;\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n/**\n * Same than `YError.wrap()` but preserves the code\n * and the debug values of the error if it is\n * already an instance of the YError constructor.\n * @param {Error} err\n * The error to bump\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.bump = function yerrorBump(err, ...params) {\n if (_looksLikeAYError(err)) {\n return YError.wrap.apply(YError, [err, err.code].concat(err.params));\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n// In order to keep compatibility through major versions\n// we have to make kind of an cross major version instanceof\nfunction _looksLikeAYError(err) {\n return (\n err instanceof YError ||\n (err.constructor &&\n err.constructor.name &&\n err.constructor.name.endsWith('Error') &&\n 'string' === typeof err.code &&\n _looksLikeAYErrorCode(err.code) &&\n err.params &&\n err.params instanceof Array)\n );\n}\n\nfunction _looksL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,KAAZ,CAAkB3B,MAAlB,EAA0B,CAACkB,GAAD,EAAMb,MAAN,CAAaF,MAAb,CAA1B,CAAP;AACD,CALD;;AASA,SAASuB,iBAAT,CAA2BR,GAA3B,EAAgC;EAC9B,OACEA,GAAG,YAAYlB,MAAf,IACCkB,GAAG,CAACP,WAAJ,IACCO,GAAG,CAACP,WAAJ,CAAgBJ,IADjB,IAECW,GAAG,CAACP,WAAJ,CAAgBJ,IAAhB,CAAqBuB,QAArB,CAA8B,OAA9B,CAFD,IAGC,aAAa,OAAOZ,GAAG,CAACZ,IAHzB,IAICe,qBAAqB,CAACH,GAAG,CAACZ,IAAL,CAJtB,IAKCY,GAAG,CAACf,MALL,IAMCe,GAAG,CAACf,MAAJ,YAAsBC,KAR1B;AAUD;;AAED,SAASiB,qBAAT,CAA+BU,GAA/B,EAAoC;EAClC,OAAO,iBAAiBC,IAAjB,CAAsBD,GAAtB,CAAP;AACD;;AAED,eAAe/B,MAAf"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["os","YError","wrappedErrors","errorCode","params","Array","concat","code","name","toString","Error","captureStackTrace","constructor","length","stack","EOL","join","wrap","yerrorWrap","err","yError","wrappedErrorIsACode","_looksLikeAYErrorCode","message","push","cast","yerrorCast","_looksLikeAYError","apply","bump","yerrorBump","endsWith","str","test"],"sources":["../src/index.js"],"sourcesContent":["import os from 'os';\n\n/**\n * An YError class able to contain some params and\n * print better stack traces\n * @extends Error\n */\nclass YError extends Error {\n /**\n * Creates a new YError with an error code\n * and some params as debug values.\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n */\n constructor(wrappedErrors, errorCode, ...params) {\n // Detecting if wrappedErrors are passed\n if (!(wrappedErrors instanceof Array)) {\n params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(\n params,\n );\n errorCode = wrappedErrors;\n wrappedErrors = [];\n }\n\n // Call the parent constructor\n super(errorCode);\n\n // Filling error\n this.code = errorCode || 'E_UNEXPECTED';\n this.params = params;\n this.wrappedErrors = wrappedErrors;\n this.name = this.toString();\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n toString() {\n return (\n (this.wrappedErrors.length\n ? // eslint-disable-next-line\n this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL\n : '') +\n this.constructor.name +\n ': ' +\n this.code +\n ' (' +\n this.params.join(', ') +\n ')'\n );\n }\n}\n\n/**\n * Wraps any error and output a YError with an error\n * code and some params as debug values.\n * @param {Error} err\n * The error to wrap\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.wrap = function yerrorWrap(err, errorCode, ...params) {\n let yError = null;\n const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);\n const wrappedErrors = (err.wrappedErrors || []).concat(err);\n\n if (!errorCode) {\n if (wrappedErrorIsACode) {\n errorCode = err.message;\n } else {\n errorCode = 'E_UNEXPECTED';\n }\n }\n if (err.message && !wrappedErrorIsACode) {\n params.push(err.message);\n }\n yError = new YError(wrappedErrors, errorCode, ...params);\n return yError;\n};\n\n/**\n * Return a YError as is or wraps any other error and output\n * a YError with a code and some params as debug values.\n * @param {Error} err\n * The error to cast\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.cast = function yerrorCast(err, ...params) {\n if (_looksLikeAYError(err)) {\n return err;\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n/**\n * Same than `YError.wrap()` but preserves the code\n * and the debug values of the error if it is\n * already an instance of the YError constructor.\n * @param {Error} err\n * The error to bump\n * @param {string} [errorCode = 'E_UNEXPECTED']\n * The error code corresponding to the actual error\n * @param {...any} [params]\n * Some additional debugging values\n * @return {YError}\n * The wrapped error\n */\nYError.bump = function yerrorBump(err, ...params) {\n if (_looksLikeAYError(err)) {\n return YError.wrap.apply(YError, [err, err.code].concat(err.params));\n }\n return YError.wrap.apply(YError, [err].concat(params));\n};\n\n// In order to keep compatibility through major versions\n// we have to make kind of an cross major version instanceof\nfunction _looksLikeAYError(err) {\n return (\n err instanceof YError ||\n (err.constructor &&\n err.constructor.name &&\n err.constructor.name.endsWith('Error') &&\n 'string' === typeof err.code &&\n _looksLikeAYErrorCode(err.code) &&\n err.params &&\n err.params instanceof Array)\n );\n}\n\nfunction _looksLikeAYErrorCode(str) {\n return /^([A-Z0-9_]+)$/.test(str);\n}\n\nexport default YError;\nexport { YError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,EAAP,MAAe,IAAf;;IAOMC,M;;;EASJ,gBAAYC,aAAZ,EAA2BC,SAA3B,EAAsC,GAAGC,MAAzC,EAAiD;IAAA;;IAAA;;IAE/C,IAAI,EAAEF,aAAa,YAAYG,KAA3B,CAAJ,EAAuC;MACrCD,MAAM,GAAG,CAAC,gBAAgB,OAAOD,SAAvB,GAAmC,EAAnC,GAAwC,CAACA,SAAD,CAAzC,EAAsDG,MAAtD,CACPF,MADO,CAAT;MAGAD,SAAS,GAAGD,aAAZ;MACAA,aAAa,GAAG,EAAhB;IACD;;IAGD,4EAAMC,SAAN;IAGA,MAAKI,IAAL,GAAYJ,SAAS,IAAI,cAAzB;IACA,MAAKC,MAAL,GAAcA,MAAd;IACA,MAAKF,aAAL,GAAqBA,aAArB;IACA,MAAKM,IAAL,GAAY,MAAKC,QAAL,EAAZ;;IAEA,IAAIC,KAAK,CAACC,iBAAV,EAA6B;MAC3BD,KAAK,CAACC,iBAAN,gCAA8B,MAAKC,WAAnC;IACD;;IArB8C;EAsBhD;;;;+BAEU;MACT,OACE,CAAC,KAAKV,aAAL,CAAmBW,MAAnB,GAEG,KAAKX,aAAL,CAAmB,KAAKA,aAAL,CAAmBW,MAAnB,GAA4B,CAA/C,EAAkDC,KAAlD,GAA0Dd,EAA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