yerror 6.2.1 → 7.0.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 CHANGED
@@ -1,3 +1,7 @@
1
+ # [7.0.0](https://github.com/nfroidure/yerror/compare/v6.2.1...v7.0.0) (2023-08-11)
2
+
3
+
4
+
1
5
  ## [6.2.1](https://github.com/nfroidure/yerror/compare/v6.2.0...v6.2.1) (2022-12-19)
2
6
 
3
7
 
package/README.md CHANGED
@@ -7,9 +7,8 @@
7
7
  # yerror
8
8
  > It helps to know why you got an error.
9
9
 
10
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/yerror/blob/master/LICENSE)
11
- [![Build status](https://travis-ci.com/git://github.com/nfroidure/yerror.git.svg?branch=master)](https://travis-ci.com/github/git://github.com/nfroidure/yerror.git)
12
- [![Coverage Status](https://coveralls.io/repos/github/git://github.com/nfroidure/yerror.git/badge.svg?branch=master)](https://coveralls.io/github/git://github.com/nfroidure/yerror.git?branch=master)
10
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/yerror/blob/main/LICENSE)
11
+ [![Coverage Status](https://coveralls.io/repos/github/git://github.com/nfroidure/yerror.git/badge.svg?branch=main)](https://coveralls.io/github/git://github.com/nfroidure/yerror.git?branch=main)
13
12
 
14
13
 
15
14
  [//]: # (::contents:start)
@@ -80,7 +79,7 @@ doSomethingAsync('nuts', 'code')
80
79
 
81
80
  <dl>
82
81
  <dt><a href="#YError">YError</a> ⇐ <code>Error</code></dt>
83
- <dd><p>An YError class able to contain some params and
82
+ <dd><p>A YError class able to contain some params and
84
83
  print better stack traces</p>
85
84
  </dd>
86
85
  </dl>
@@ -97,30 +96,17 @@ doSomethingAsync('nuts', 'code')
97
96
  <a name="YError"></a>
98
97
 
99
98
  ## YError ⇐ <code>Error</code>
100
- An YError class able to contain some params and
99
+ A YError class able to contain some params and
101
100
  print better stack traces
102
101
 
103
102
  **Kind**: global class
104
103
  **Extends**: <code>Error</code>
105
104
 
106
105
  * [YError](#YError) ⇐ <code>Error</code>
107
- * [new YError([errorCode], [...params])](#new_YError_new)
108
106
  * [.wrap(err, [errorCode], [...params])](#YError.wrap) ⇒ [<code>YError</code>](#YError)
109
107
  * [.cast(err, [errorCode], [...params])](#YError.cast) ⇒ [<code>YError</code>](#YError)
110
108
  * [.bump(err, [errorCode], [...params])](#YError.bump) ⇒ [<code>YError</code>](#YError)
111
109
 
112
- <a name="new_YError_new"></a>
113
-
114
- ### new YError([errorCode], [...params])
115
- Creates a new YError with an error code
116
- and some params as debug values.
117
-
118
-
119
- | Param | Type | Default | Description |
120
- | --- | --- | --- | --- |
121
- | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
122
- | [...params] | <code>any</code> | | Some additional debugging values |
123
-
124
110
  <a name="YError.wrap"></a>
125
111
 
126
112
  ### YError.wrap(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)
@@ -134,7 +120,7 @@ Wraps any error and output a YError with an error
134
120
  | --- | --- | --- | --- |
135
121
  | err | <code>Error</code> | | The error to wrap |
136
122
  | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
137
- | [...params] | <code>any</code> | | Some additional debugging values |
123
+ | [...params] | <code>YErrorParams</code> | | Some additional debugging values |
138
124
 
139
125
  <a name="YError.cast"></a>
140
126
 
@@ -149,7 +135,7 @@ Return a YError as is or wraps any other error and output
149
135
  | --- | --- | --- | --- |
150
136
  | err | <code>Error</code> | | The error to cast |
151
137
  | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
152
- | [...params] | <code>any</code> | | Some additional debugging values |
138
+ | [...params] | <code>YErrorParams</code> | | Some additional debugging values |
153
139
 
154
140
  <a name="YError.bump"></a>
155
141
 
@@ -165,7 +151,7 @@ Same than `YError.wrap()` but preserves the code
165
151
  | --- | --- | --- | --- |
166
152
  | err | <code>Error</code> | | The error to bump |
167
153
  | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
168
- | [...params] | <code>any</code> | | Some additional debugging values |
154
+ | [...params] | <code>YErrorParams</code> | | Some additional debugging values |
169
155
 
170
156
  <a name="printStackTrace"></a>
171
157
 
@@ -185,4 +171,4 @@ Allow to print a stack from anything (especially catched
185
171
  - [Nicolas Froidure (formerly at SimpliField)](http://insertafter.com/en/index.html)
186
172
 
187
173
  # License
188
- [MIT](https://github.com/nfroidure/yerror/blob/master/LICENSE)
174
+ [MIT](https://github.com/nfroidure/yerror/blob/main/LICENSE)
@@ -0,0 +1,72 @@
1
+ type YErrorParams = any;
2
+ /**
3
+ * A YError class able to contain some params and
4
+ * print better stack traces
5
+ * @extends Error
6
+ */
7
+ declare class YError extends Error {
8
+ code: string;
9
+ params: YErrorParams[];
10
+ wrappedErrors: (Error | YError)[];
11
+ /**
12
+ * Creates a new YError with an error code
13
+ * and some params as debug values.
14
+ * @param {string} [errorCode = 'E_UNEXPECTED']
15
+ * The error code corresponding to the actual error
16
+ * @param {...YErrorParams} [params]
17
+ * Some additional debugging values
18
+ */
19
+ constructor(errorCode: string, ...params: YErrorParams[]);
20
+ constructor(wrappedErrors?: Error[], errorCode?: string, ...params: YErrorParams[]);
21
+ /**
22
+ * Wraps any error and output a YError with an error
23
+ * code and some params as debug values.
24
+ * @param {Error} err
25
+ * The error to wrap
26
+ * @param {string} [errorCode = 'E_UNEXPECTED']
27
+ * The error code corresponding to the actual error
28
+ * @param {...YErrorParams} [params]
29
+ * Some additional debugging values
30
+ * @return {YError}
31
+ * The wrapped error
32
+ */
33
+ static wrap<E extends Error | YError>(err: E, errorCode?: string, ...params: YErrorParams[]): YError;
34
+ /**
35
+ * Return a YError as is or wraps any other error and output
36
+ * a YError with a code and some params as debug values.
37
+ * @param {Error} err
38
+ * The error to cast
39
+ * @param {string} [errorCode = 'E_UNEXPECTED']
40
+ * The error code corresponding to the actual error
41
+ * @param {...YErrorParams} [params]
42
+ * Some additional debugging values
43
+ * @return {YError}
44
+ * The wrapped error
45
+ */
46
+ static cast<E extends Error | YError>(err: E, errorCode?: string, ...params: YErrorParams[]): YError;
47
+ /**
48
+ * Same than `YError.wrap()` but preserves the code
49
+ * and the debug values of the error if it is
50
+ * already an instance of the YError constructor.
51
+ * @param {Error} err
52
+ * The error to bump
53
+ * @param {string} [errorCode = 'E_UNEXPECTED']
54
+ * The error code corresponding to the actual error
55
+ * @param {...YErrorParams} [params]
56
+ * Some additional debugging values
57
+ * @return {YError}
58
+ * The wrapped error
59
+ */
60
+ static bump<E extends Error | YError>(err: E, errorCode?: string, ...params: YErrorParams[]): YError;
61
+ toString(): string;
62
+ }
63
+ /**
64
+ * Allow to print a stack from anything (especially catched
65
+ * errors that may or may not contain errors 🤷).
66
+ * @param {Error} err
67
+ * The error to print
68
+ * @return {string}
69
+ * The stack trace if any
70
+ */
71
+ export declare function printStackTrace(err: Error | YError): string;
72
+ export { YError };
package/dist/index.js CHANGED
@@ -1,173 +1,109 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.YError = void 0;
7
- exports.printStackTrace = printStackTrace;
8
-
9
- var _os = _interopRequireDefault(require("os"));
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
-
15
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
16
-
17
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
18
-
19
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
20
-
21
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
-
23
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
-
25
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
26
-
27
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
28
-
29
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
30
-
31
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
32
-
33
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
34
-
35
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
36
-
1
+ import os from 'os';
37
2
  /**
38
- * An YError class able to contain some params and
3
+ * A YError class able to contain some params and
39
4
  * print better stack traces
40
5
  * @extends Error
41
6
  */
42
- let YError = /*#__PURE__*/function (_Error) {
43
- _inherits(YError, _Error);
44
-
45
- /**
46
- * Creates a new YError with an error code
47
- * and some params as debug values.
48
- * @param {string} [errorCode = 'E_UNEXPECTED']
49
- * The error code corresponding to the actual error
50
- * @param {...any} [params]
51
- * Some additional debugging values
52
- */
53
- function YError(wrappedErrors, errorCode, ...params) {
54
- var _this;
55
-
56
- _classCallCheck(this, YError);
57
-
58
- // Detecting if wrappedErrors are passed
59
- if (!(wrappedErrors instanceof Array)) {
60
- params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(params);
61
- errorCode = wrappedErrors;
62
- wrappedErrors = [];
63
- } // Call the parent constructor
64
-
65
-
66
- _this = _possibleConstructorReturn(this, _getPrototypeOf(YError).call(this, errorCode)); // Filling error
67
-
68
- _this.code = errorCode || 'E_UNEXPECTED';
69
- _this.params = params;
70
- _this.wrappedErrors = wrappedErrors;
71
- _this.name = _this.toString();
72
-
73
- if (Error.captureStackTrace) {
74
- Error.captureStackTrace(_assertThisInitialized(_this), _this.constructor);
7
+ class YError extends Error {
8
+ code;
9
+ params;
10
+ wrappedErrors;
11
+ constructor(wrappedErrors, errorCode, ...params) {
12
+ // Detecting if wrappedErrors are passed
13
+ if (!(wrappedErrors instanceof Array)) {
14
+ params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(params);
15
+ errorCode = wrappedErrors;
16
+ wrappedErrors = [];
17
+ }
18
+ // Call the parent constructor
19
+ super(errorCode);
20
+ // Filling error
21
+ this.code = errorCode || 'E_UNEXPECTED';
22
+ this.params = params;
23
+ this.wrappedErrors = wrappedErrors;
24
+ this.name = this.toString();
25
+ if (Error.captureStackTrace) {
26
+ Error.captureStackTrace(this, this.constructor);
27
+ }
75
28
  }
76
-
77
- return _this;
78
- }
79
-
80
- _createClass(YError, [{
81
- key: "toString",
82
- value: function toString() {
83
- return (this.wrappedErrors.length ? // eslint-disable-next-line
84
- this.wrappedErrors[this.wrappedErrors.length - 1].stack + _os.default.EOL : '') + this.constructor.name + ': ' + this.code + ' (' + this.params.join(', ') + ')';
29
+ /**
30
+ * Wraps any error and output a YError with an error
31
+ * code and some params as debug values.
32
+ * @param {Error} err
33
+ * The error to wrap
34
+ * @param {string} [errorCode = 'E_UNEXPECTED']
35
+ * The error code corresponding to the actual error
36
+ * @param {...YErrorParams} [params]
37
+ * Some additional debugging values
38
+ * @return {YError}
39
+ * The wrapped error
40
+ */
41
+ static wrap(err, errorCode, ...params) {
42
+ const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
43
+ const wrappedErrors = ('wrappedErrors' in err ? err.wrappedErrors : []).concat(err);
44
+ if (!errorCode) {
45
+ if (wrappedErrorIsACode) {
46
+ errorCode = err.message;
47
+ }
48
+ else {
49
+ errorCode = 'E_UNEXPECTED';
50
+ }
51
+ }
52
+ if (err.message && !wrappedErrorIsACode) {
53
+ params.push(err.message);
54
+ }
55
+ return new YError(wrappedErrors, errorCode, ...params);
85
56
  }
86
- }]);
87
-
88
- return YError;
89
- }(_wrapNativeSuper(Error));
90
- /**
91
- * Wraps any error and output a YError with an error
92
- * code and some params as debug values.
93
- * @param {Error} err
94
- * The error to wrap
95
- * @param {string} [errorCode = 'E_UNEXPECTED']
96
- * The error code corresponding to the actual error
97
- * @param {...any} [params]
98
- * Some additional debugging values
99
- * @return {YError}
100
- * The wrapped error
101
- */
102
-
103
-
104
- exports.YError = YError;
105
-
106
- YError.wrap = function yerrorWrap(err, errorCode, ...params) {
107
- let yError = null;
108
-
109
- const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
110
-
111
- const wrappedErrors = (err.wrappedErrors || []).concat(err);
112
-
113
- if (!errorCode) {
114
- if (wrappedErrorIsACode) {
115
- errorCode = err.message;
116
- } else {
117
- errorCode = 'E_UNEXPECTED';
57
+ /**
58
+ * Return a YError as is or wraps any other error and output
59
+ * a YError with a code and some params as debug values.
60
+ * @param {Error} err
61
+ * The error to cast
62
+ * @param {string} [errorCode = 'E_UNEXPECTED']
63
+ * The error code corresponding to the actual error
64
+ * @param {...YErrorParams} [params]
65
+ * Some additional debugging values
66
+ * @return {YError}
67
+ * The wrapped error
68
+ */
69
+ static cast(err, errorCode, ...params) {
70
+ if (_looksLikeAYError(err)) {
71
+ return err;
72
+ }
73
+ return YError.wrap(err, errorCode, ...params);
118
74
  }
119
- }
120
-
121
- if (err.message && !wrappedErrorIsACode) {
122
- params.push(err.message);
123
- }
124
-
125
- yError = new YError(wrappedErrors, errorCode, ...params);
126
- return yError;
127
- };
128
- /**
129
- * Return a YError as is or wraps any other error and output
130
- * a YError with a code and some params as debug values.
131
- * @param {Error} err
132
- * The error to cast
133
- * @param {string} [errorCode = 'E_UNEXPECTED']
134
- * The error code corresponding to the actual error
135
- * @param {...any} [params]
136
- * Some additional debugging values
137
- * @return {YError}
138
- * The wrapped error
139
- */
140
-
141
-
142
- YError.cast = function yerrorCast(err, ...params) {
143
- if (_looksLikeAYError(err)) {
144
- return err;
145
- }
146
-
147
- return YError.wrap.apply(YError, [err].concat(params));
148
- };
149
- /**
150
- * Same than `YError.wrap()` but preserves the code
151
- * and the debug values of the error if it is
152
- * already an instance of the YError constructor.
153
- * @param {Error} err
154
- * The error to bump
155
- * @param {string} [errorCode = 'E_UNEXPECTED']
156
- * The error code corresponding to the actual error
157
- * @param {...any} [params]
158
- * Some additional debugging values
159
- * @return {YError}
160
- * The wrapped error
161
- */
162
-
163
-
164
- YError.bump = function yerrorBump(err, ...params) {
165
- if (_looksLikeAYError(err)) {
166
- return YError.wrap.apply(YError, [err, err.code].concat(err.params));
167
- }
168
-
169
- return YError.wrap.apply(YError, [err].concat(params));
170
- };
75
+ /**
76
+ * Same than `YError.wrap()` but preserves the code
77
+ * and the debug values of the error if it is
78
+ * already an instance of the YError constructor.
79
+ * @param {Error} err
80
+ * The error to bump
81
+ * @param {string} [errorCode = 'E_UNEXPECTED']
82
+ * The error code corresponding to the actual error
83
+ * @param {...YErrorParams} [params]
84
+ * Some additional debugging values
85
+ * @return {YError}
86
+ * The wrapped error
87
+ */
88
+ static bump(err, errorCode, ...params) {
89
+ if (_looksLikeAYError(err)) {
90
+ return YError.wrap(err, err.code, ...err.params);
91
+ }
92
+ return YError.wrap(err, errorCode, ...params);
93
+ }
94
+ toString() {
95
+ return ((this.wrappedErrors.length
96
+ ? // eslint-disable-next-line
97
+ this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL
98
+ : '') +
99
+ this.constructor.name +
100
+ ': ' +
101
+ this.code +
102
+ ' (' +
103
+ this.params.join(', ') +
104
+ ')');
105
+ }
106
+ }
171
107
  /**
172
108
  * Allow to print a stack from anything (especially catched
173
109
  * errors that may or may not contain errors 🤷).
@@ -176,22 +112,29 @@ YError.bump = function yerrorBump(err, ...params) {
176
112
  * @return {string}
177
113
  * The stack trace if any
178
114
  */
179
-
180
-
181
- function printStackTrace(err) {
182
- return typeof err === 'object' && typeof err.stack === 'string' ? err.stack : `[no_stack_trace]: error is ${err != null && typeof err.toString === 'function' ? err.toString() : typeof err}`;
183
- } // In order to keep compatibility through major versions
115
+ export function printStackTrace(err) {
116
+ return typeof err === 'object' && typeof err.stack === 'string'
117
+ ? err.stack
118
+ : `[no_stack_trace]: error is ${err != null && typeof err.toString === 'function'
119
+ ? err.toString()
120
+ : typeof err}`;
121
+ }
122
+ // In order to keep compatibility through major versions
184
123
  // we have to make kind of an cross major version instanceof
185
-
186
-
187
124
  function _looksLikeAYError(err) {
188
- return err instanceof YError || err.constructor && err.constructor.name && err.constructor.name.endsWith('Error') && 'string' === typeof err.code && _looksLikeAYErrorCode(err.code) && err.params && err.params instanceof Array;
125
+ return (!!(err instanceof YError) ||
126
+ !!(err.constructor &&
127
+ err.constructor.name &&
128
+ err.constructor.name.endsWith('Error') &&
129
+ 'code' in err &&
130
+ 'string' === typeof err.code &&
131
+ _looksLikeAYErrorCode(err.code) &&
132
+ 'params' in err &&
133
+ err.params &&
134
+ err.params instanceof Array));
189
135
  }
190
-
191
136
  function _looksLikeAYErrorCode(str) {
192
- return /^([A-Z0-9_]+)$/.test(str);
137
+ return /^([A-Z0-9_]+)$/.test(str);
193
138
  }
194
-
195
- var _default = YError;
196
- exports.default = _default;
139
+ export { YError };
197
140
  //# sourceMappingURL=index.js.map
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","printStackTrace","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/**\n * Allow to print a stack from anything (especially catched\n * errors that may or may not contain errors 🤷).\n * @param {Error} err\n * The error to print\n * @return {string}\n * The stack trace if any\n */\nexport function printStackTrace(err) {\n return typeof err === 'object' && typeof err.stack === 'string'\n ? err.stack\n : `[no_stack_trace]: error is ${\n err != null && typeof err.toString === 'function'\n ? err.toString()\n : typeof err\n }`;\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,G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