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 +4 -0
- package/README.md +8 -22
- package/dist/index.d.ts +72 -0
- package/dist/index.js +119 -176
- package/dist/index.js.map +1 -1
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +145 -0
- package/dist/index.test.js.map +1 -0
- package/package.json +89 -71
- package/src/{index.mocha.js → index.test.ts} +74 -55
- package/src/index.ts +192 -0
- package/dist/index.mjs +0 -117
- package/dist/index.mjs.map +0 -1
- package/dist/index.mocha.js +0 -201
- package/dist/index.mocha.js.map +0 -1
- package/dist/index.mocha.mjs +0 -153
- package/dist/index.mocha.mjs.map +0 -1
- package/src/index.d.ts +0 -26
- package/src/index.js +0 -165
package/CHANGELOG.md
CHANGED
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
|
-
[](https://github.com/nfroidure/yerror/blob/
|
|
11
|
-
[](https://coveralls.io/github/git://github.com/nfroidure/yerror.git?branch=master)
|
|
10
|
+
[](https://github.com/nfroidure/yerror/blob/main/LICENSE)
|
|
11
|
+
[](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>
|
|
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
|
-
|
|
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>"'E_UNEXPECTED'"</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>"'E_UNEXPECTED'"</code> | The error code corresponding to the actual error |
|
|
137
|
-
| [...params] | <code>
|
|
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>"'E_UNEXPECTED'"</code> | The error code corresponding to the actual error |
|
|
152
|
-
| [...params] | <code>
|
|
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>"'E_UNEXPECTED'"</code> | The error code corresponding to the actual error |
|
|
168
|
-
| [...params] | <code>
|
|
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/
|
|
174
|
+
[MIT](https://github.com/nfroidure/yerror/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -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
|
-
|
|
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
|
-
*
|
|
3
|
+
* A YError class able to contain some params and
|
|
39
4
|
* print better stack traces
|
|
40
5
|
* @extends Error
|
|
41
6
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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","
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAKpB;;;;GAIG;AACH,MAAM,MAAO,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,MAAM,CAAiB;IACvB,aAAa,CAAqB;IAelC,YAAY,aAAa,EAAE,SAAS,EAAE,GAAG,MAAM;QAC7C,wCAAwC;QACxC,IAAI,CAAC,CAAC,aAAa,YAAY,KAAK,CAAC,EAAE;YACrC,MAAM,GAAG,CAAC,WAAW,KAAK,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CACnE,MAAM,CACP,CAAC;YACF,SAAS,GAAG,aAAa,CAAC;YAC1B,aAAa,GAAG,EAAE,CAAC;SACpB;QAED,8BAA8B;QAC9B,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,gBAAgB;QAChB,IAAI,CAAC,IAAI,GAAG,SAAS,IAAI,cAAc,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAE5B,IAAI,KAAK,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SACjD;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,IAAI,CACT,GAAM,EACN,SAAkB,EAClB,GAAG,MAAsB;QAEzB,MAAM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