yerror 5.0.0 → 6.0.2

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +4 -5
  3. package/README.md +85 -22
  4. package/dist/index.js +83 -43
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +112 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/index.mocha.js +143 -100
  9. package/dist/index.mocha.js.map +1 -0
  10. package/dist/index.mocha.mjs +153 -0
  11. package/dist/index.mocha.mjs.map +1 -0
  12. package/package.json +173 -49
  13. package/src/index.js +52 -4
  14. package/src/index.mocha.js +2 -2
  15. package/.gitattributes +0 -2
  16. package/.nyc_output/00dc2184-5e3c-4e30-a46f-ae7cc1a69a02.json +0 -1
  17. package/.nyc_output/0ede01fe-53e1-435f-b3eb-1df8f8683022.json +0 -1
  18. package/.nyc_output/32a94c4b-415d-42f2-80ae-02e2299d2d09.json +0 -1
  19. package/.nyc_output/5964f491-ff21-4d82-9065-4d98a1cf2a72.json +0 -1
  20. package/.nyc_output/753f19e8-b00d-40af-86d4-f5c7460a8512.json +0 -1
  21. package/.nyc_output/7b3668dc-e84a-4597-aa9a-7a9ca79a4a0b.json +0 -1
  22. package/.nyc_output/97c4112e-25f6-4fa9-8e45-2470696afd0c.json +0 -1
  23. package/.nyc_output/a41790e4-963e-4810-82b3-ea3f1fd3ed42.json +0 -1
  24. package/.nyc_output/a711db83-691b-44a5-9cf0-5bd5d791c358.json +0 -1
  25. package/.nyc_output/a7863a34-92ff-47f2-acd5-268fc48d9114.json +0 -1
  26. package/.nyc_output/aa7b6383-4b7d-4873-ab12-665ec47b5ea4.json +0 -1
  27. package/.nyc_output/c1c442d7-7a0e-4982-8526-03f1bd400806.json +0 -1
  28. package/.nyc_output/c32e5e08-dc5b-4e45-a433-2cf0e9d350c9.json +0 -1
  29. package/.nyc_output/c3b5498e-d857-46b9-afa5-2ea3fd21bd4e.json +0 -1
  30. package/.nyc_output/c47902c8-d5f8-489e-b13e-000ea5dc7636.json +0 -1
  31. package/.nyc_output/cd492b94-ca79-4b8d-8ca3-15ac79ac99f6.json +0 -1
  32. package/.nyc_output/d371f8f1-bbcf-4712-b71c-c839582c672a.json +0 -1
  33. package/.nyc_output/fb7d1240-39cc-42b7-835f-6e39d9501a68.json +0 -1
  34. package/.nyc_output/processinfo/00dc2184-5e3c-4e30-a46f-ae7cc1a69a02.json +0 -1
  35. package/.nyc_output/processinfo/0ede01fe-53e1-435f-b3eb-1df8f8683022.json +0 -1
  36. package/.nyc_output/processinfo/32a94c4b-415d-42f2-80ae-02e2299d2d09.json +0 -1
  37. package/.nyc_output/processinfo/5964f491-ff21-4d82-9065-4d98a1cf2a72.json +0 -1
  38. package/.nyc_output/processinfo/753f19e8-b00d-40af-86d4-f5c7460a8512.json +0 -1
  39. package/.nyc_output/processinfo/7b3668dc-e84a-4597-aa9a-7a9ca79a4a0b.json +0 -1
  40. package/.nyc_output/processinfo/97c4112e-25f6-4fa9-8e45-2470696afd0c.json +0 -1
  41. package/.nyc_output/processinfo/a41790e4-963e-4810-82b3-ea3f1fd3ed42.json +0 -1
  42. package/.nyc_output/processinfo/a711db83-691b-44a5-9cf0-5bd5d791c358.json +0 -1
  43. package/.nyc_output/processinfo/a7863a34-92ff-47f2-acd5-268fc48d9114.json +0 -1
  44. package/.nyc_output/processinfo/aa7b6383-4b7d-4873-ab12-665ec47b5ea4.json +0 -1
  45. package/.nyc_output/processinfo/c1c442d7-7a0e-4982-8526-03f1bd400806.json +0 -1
  46. package/.nyc_output/processinfo/c32e5e08-dc5b-4e45-a433-2cf0e9d350c9.json +0 -1
  47. package/.nyc_output/processinfo/c3b5498e-d857-46b9-afa5-2ea3fd21bd4e.json +0 -1
  48. package/.nyc_output/processinfo/c47902c8-d5f8-489e-b13e-000ea5dc7636.json +0 -1
  49. package/.nyc_output/processinfo/cd492b94-ca79-4b8d-8ca3-15ac79ac99f6.json +0 -1
  50. package/.nyc_output/processinfo/d371f8f1-bbcf-4712-b71c-c839582c672a.json +0 -1
  51. package/.nyc_output/processinfo/fb7d1240-39cc-42b7-835f-6e39d9501a68.json +0 -1
  52. package/.nyc_output/processinfo/index.json +0 -1
  53. package/.travis.yml +0 -11
  54. package/karma.conf.js +0 -127
  55. package/sauce_connect.log +0 -436
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## [6.0.2](https://github.com/nfroidure/yerror/compare/v6.0.1...v6.0.2) (2022-05-25)
2
+
3
+
4
+
5
+ ## [6.0.1](https://github.com/nfroidure/yerror/compare/v6.0.0...v6.0.1) (2021-04-10)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **types:** fix types declarations path ([da5344d](https://github.com/nfroidure/yerror/commit/da5344ddc3aa47f0867a1cc720f0bde02943932a))
11
+
12
+
13
+
14
+ # [6.0.0](https://github.com/nfroidure/yerror/compare/v5.0.0...v6.0.0) (2021-04-09)
15
+
16
+
17
+
package/LICENSE CHANGED
@@ -1,9 +1,8 @@
1
- The MIT License
2
-
3
- Copyright (c) SimpliField, <http://simplifield.com/>
1
+ The MIT License (MIT)
2
+ Copyright © 2017 Nicolas Froidure (formerly at SimpliField)
4
3
 
5
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
5
+ of this software and associated documentation files (the Software), to deal
7
6
  in the Software without restriction, including without limitation the rights
8
7
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
8
  copies of the Software, and to permit persons to whom the Software is
@@ -12,7 +11,7 @@ furnished to do so, subject to the following conditions:
12
11
  The above copyright notice and this permission notice shall be included in
13
12
  all copies or substantial portions of the Software.
14
13
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ THE SOFTWARE IS PROVIDED AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
15
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
16
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
17
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
package/README.md CHANGED
@@ -1,15 +1,25 @@
1
- # YError
2
- > Better errors for your NodeJS code.
1
+ [//]: # ( )
2
+ [//]: # (This file is automatically generated by a `metapak`)
3
+ [//]: # (module. Do not change it except between the)
4
+ [//]: # (`content:start/end` flags, your changes would)
5
+ [//]: # (be overridden.)
6
+ [//]: # ( )
7
+ # yerror
8
+ > It helps to know why you got an error.
3
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)
4
13
 
5
- [![NPM version](https://badge.fury.io/js/yerror.svg)](https://npmjs.org/package/yerror) [![Build status](https://secure.travis-ci.org/nfroidure/yerror.png)](https://travis-ci.org/nfroidure/yerror) [![Dependency Status](https://david-dm.org/nfroidure/yerror/status.svg)](https://david-dm.org/nfroidure/yerror) [![devDependency Status](https://david-dm.org/nfroidure/yerror/dev-status.svg)](https://david-dm.org/nfroidure/yerror#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/nfroidure/yerror/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/yerror?branch=master) [![Code Climate](https://codeclimate.com/github/nfroidure/yerror.png)](https://codeclimate.com/github/nfroidure/yerror)
14
+
15
+ [//]: # (::contents:start)
6
16
 
7
17
  ## Usage
8
18
 
9
19
  First, require me where you could throw errors:
10
20
 
11
21
  ```js
12
- var YError = require('yerror');
22
+ import YError from 'yerror';
13
23
  ```
14
24
 
15
25
  Then, emit errors with a bonus: parameters!
@@ -28,11 +38,10 @@ doSomething('nuts', 'code');
28
38
  // at doSomething (/home/nfroidure/nfroidure/yerror/test.js:5:11)
29
39
  // at Object.<anonymous> (/home/nfroidure/nfroidure/yerror/test.js:9:1)
30
40
  // (...)
31
-
32
41
  ```
33
42
 
34
43
  You don't have to use constant like error messages, we use this convention
35
- mainly for i18n reasons.
44
+ mainly for i18n reasons.
36
45
 
37
46
  Also, you could want to wrap errors and keep a valuable stack trace:
38
47
 
@@ -61,34 +70,88 @@ doSomethingAsync('nuts', 'code')
61
70
  // at /home/nfroidure/nfroidure/yerror/test.js:16:21
62
71
  // at doSomethingAsync (/home/nfroidure/nfroidure/yerror/test.js:11:11)
63
72
  // (...)
73
+ ```
64
74
 
65
75
 
66
- ```
76
+ [//]: # (::contents:end)
77
+
78
+ # API
79
+ <a name="YError"></a>
80
+
81
+ ## YError ⇐ <code>Error</code>
82
+ An YError class able to contain some params and
83
+ print better stack traces
84
+
85
+ **Kind**: global class
86
+ **Extends**: <code>Error</code>
87
+
88
+ * [YError](#YError) ⇐ <code>Error</code>
89
+ * [new YError([errorCode], [...params])](#new_YError_new)
90
+ * [.wrap(err, [errorCode], [...params])](#YError.wrap) ⇒ [<code>YError</code>](#YError)
91
+ * [.cast(err, [errorCode], [...params])](#YError.cast) ⇒ [<code>YError</code>](#YError)
92
+ * [.bump(err, [errorCode], [...params])](#YError.bump) ⇒ [<code>YError</code>](#YError)
93
+
94
+ <a name="new_YError_new"></a>
95
+
96
+ ### new YError([errorCode], [...params])
97
+ Creates a new YError with an error code
98
+ and some params as debug values.
99
+
100
+
101
+ | Param | Type | Default | Description |
102
+ | --- | --- | --- | --- |
103
+ | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
104
+ | [...params] | <code>any</code> | | Some additional debugging values |
105
+
106
+ <a name="YError.wrap"></a>
107
+
108
+ ### YError.wrap(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)
109
+ Wraps any error and output a YError with an error
110
+ code and some params as debug values.
67
111
 
68
- ## API
112
+ **Kind**: static method of [<code>YError</code>](#YError)
113
+ **Returns**: [<code>YError</code>](#YError) - The wrapped error
69
114
 
70
- ### YError(msg:String, ...args:Mixed):Error
115
+ | Param | Type | Default | Description |
116
+ | --- | --- | --- | --- |
117
+ | err | <code>Error</code> | | The error to wrap |
118
+ | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
119
+ | [...params] | <code>any</code> | | Some additional debugging values |
71
120
 
72
- Creates a new YError with `msg` as a message and `args` as debug values.
121
+ <a name="YError.cast"></a>
73
122
 
74
- ### YError.wrap(err:Error, msg:String, ...args:Mixed):Error
123
+ ### YError.cast(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)
124
+ Return a YError as is or wraps any other error and output
125
+ a YError with a code and some params as debug values.
75
126
 
76
- Wraps any error and output a YError with `msg` as its message and `args` as
77
- debug values.
127
+ **Kind**: static method of [<code>YError</code>](#YError)
128
+ **Returns**: [<code>YError</code>](#YError) - The wrapped error
78
129
 
79
- ### YError.cast(err:Error, msg:String, ...args:Mixed):Error
130
+ | Param | Type | Default | Description |
131
+ | --- | --- | --- | --- |
132
+ | err | <code>Error</code> | | The error to cast |
133
+ | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
134
+ | [...params] | <code>any</code> | | Some additional debugging values |
80
135
 
81
- Return YError as is or wraps any other error and output a YError with `msg` as
82
- its message and `args` as debug values.
136
+ <a name="YError.bump"></a>
83
137
 
84
- ### YError.bump(err:Error, fallbackMsg:String, ...fallbackArgs:Mixed):Error
138
+ ### YError.bump(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)
139
+ Same than `YError.wrap()` but preserves the code
140
+ and the debug values of the error if it is
141
+ already an instance of the YError constructor.
85
142
 
86
- Same than `YError.wrap()` but preserves the message and the debug values of the
87
- YError errors.
143
+ **Kind**: static method of [<code>YError</code>](#YError)
144
+ **Returns**: [<code>YError</code>](#YError) - The wrapped error
88
145
 
89
- ## Stats
146
+ | Param | Type | Default | Description |
147
+ | --- | --- | --- | --- |
148
+ | err | <code>Error</code> | | The error to bump |
149
+ | [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |
150
+ | [...params] | <code>any</code> | | Some additional debugging values |
90
151
 
91
- [![NPM](https://nodei.co/npm/yerror.png?downloads=true&stars=true)](https://nodei.co/npm/yerror/)
92
- [![NPM](https://nodei.co/npm-dl/yerror.png)](https://nodei.co/npm/yerror/)
93
152
 
153
+ # Authors
154
+ - [Nicolas Froidure (formerly at SimpliField)](http://insertafter.com/en/index.html)
94
155
 
156
+ # License
157
+ [MIT](https://github.com/nfroidure/yerror/blob/master/LICENSE)
package/dist/index.js CHANGED
@@ -1,46 +1,57 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _os = _interopRequireDefault(require("os"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
4
11
 
5
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
13
 
7
14
  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); } }
8
15
 
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
17
 
11
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
18
+ 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); }
12
19
 
13
20
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
21
 
15
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
+ 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); }
16
23
 
17
24
  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); }
18
25
 
19
- function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
26
+ 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); }
20
27
 
21
- function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } 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
+ 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; } }
22
29
 
23
30
  function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
24
31
 
25
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
-
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
-
29
- var os = require('os'); // Create an Error able to contain some params and better stack traces
32
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
30
33
 
34
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31
35
 
32
- var YError =
33
- /*#__PURE__*/
34
- function (_Error) {
36
+ /**
37
+ * An YError class able to contain some params and
38
+ * print better stack traces
39
+ * @extends Error
40
+ */
41
+ let YError = /*#__PURE__*/function (_Error) {
35
42
  _inherits(YError, _Error);
36
43
 
37
- function YError(wrappedErrors, errorCode) {
44
+ /**
45
+ * Creates a new YError with an error code
46
+ * and some params as debug values.
47
+ * @param {string} [errorCode = 'E_UNEXPECTED']
48
+ * The error code corresponding to the actual error
49
+ * @param {...any} [params]
50
+ * Some additional debugging values
51
+ */
52
+ function YError(wrappedErrors, errorCode, ...params) {
38
53
  var _this;
39
54
 
40
- for (var _len = arguments.length, params = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
41
- params[_key - 2] = arguments[_key];
42
- }
43
-
44
55
  _classCallCheck(this, YError);
45
56
 
46
57
  // Detecting if wrappedErrors are passed
@@ -69,20 +80,32 @@ function (_Error) {
69
80
  key: "toString",
70
81
  value: function toString() {
71
82
  return (this.wrappedErrors.length ? // eslint-disable-next-line
72
- this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL : '') + this.constructor.name + ': ' + this.code + ' (' + this.params.join(', ') + ')';
83
+ this.wrappedErrors[this.wrappedErrors.length - 1].stack + _os.default.EOL : '') + this.constructor.name + ': ' + this.code + ' (' + this.params.join(', ') + ')';
73
84
  }
74
85
  }]);
75
86
 
76
87
  return YError;
77
- }(_wrapNativeSuper(Error)); // Wrap a classic error
88
+ }(_wrapNativeSuper(Error));
89
+ /**
90
+ * Wraps any error and output a YError with an error
91
+ * code and some params as debug values.
92
+ * @param {Error} err
93
+ * The error to wrap
94
+ * @param {string} [errorCode = 'E_UNEXPECTED']
95
+ * The error code corresponding to the actual error
96
+ * @param {...any} [params]
97
+ * Some additional debugging values
98
+ * @return {YError}
99
+ * The wrapped error
100
+ */
78
101
 
79
102
 
80
- YError.wrap = function yerrorWrap(err, errorCode) {
81
- var yError = null;
103
+ YError.wrap = function yerrorWrap(err, errorCode, ...params) {
104
+ let yError = null;
82
105
 
83
- var wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
106
+ const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
84
107
 
85
- var wrappedErrors = (err.wrappedErrors || []).concat(err);
108
+ const wrappedErrors = (err.wrappedErrors || []).concat(err);
86
109
 
87
110
  if (!errorCode) {
88
111
  if (wrappedErrorIsACode) {
@@ -92,39 +115,54 @@ YError.wrap = function yerrorWrap(err, errorCode) {
92
115
  }
93
116
  }
94
117
 
95
- for (var _len2 = arguments.length, params = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
96
- params[_key2 - 2] = arguments[_key2];
97
- }
98
-
99
118
  if (err.message && !wrappedErrorIsACode) {
100
119
  params.push(err.message);
101
120
  }
102
121
 
103
- yError = _construct(YError, [wrappedErrors, errorCode].concat(params));
122
+ yError = new YError(wrappedErrors, errorCode, ...params);
104
123
  return yError;
105
124
  };
106
-
107
- YError.cast = function yerrorCast(err) {
125
+ /**
126
+ * Return a YError as is or wraps any other error and output
127
+ * a YError with a code and some params as debug values.
128
+ * @param {Error} err
129
+ * The error to cast
130
+ * @param {string} [errorCode = 'E_UNEXPECTED']
131
+ * The error code corresponding to the actual error
132
+ * @param {...any} [params]
133
+ * Some additional debugging values
134
+ * @return {YError}
135
+ * The wrapped error
136
+ */
137
+
138
+
139
+ YError.cast = function yerrorCast(err, ...params) {
108
140
  if (_looksLikeAYError(err)) {
109
141
  return err;
110
142
  }
111
143
 
112
- for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
113
- params[_key3 - 1] = arguments[_key3];
114
- }
115
-
116
144
  return YError.wrap.apply(YError, [err].concat(params));
117
145
  };
118
-
119
- YError.bump = function yerrorBump(err) {
146
+ /**
147
+ * Same than `YError.wrap()` but preserves the code
148
+ * and the debug values of the error if it is
149
+ * already an instance of the YError constructor.
150
+ * @param {Error} err
151
+ * The error to bump
152
+ * @param {string} [errorCode = 'E_UNEXPECTED']
153
+ * The error code corresponding to the actual error
154
+ * @param {...any} [params]
155
+ * Some additional debugging values
156
+ * @return {YError}
157
+ * The wrapped error
158
+ */
159
+
160
+
161
+ YError.bump = function yerrorBump(err, ...params) {
120
162
  if (_looksLikeAYError(err)) {
121
163
  return YError.wrap.apply(YError, [err, err.code].concat(err.params));
122
164
  }
123
165
 
124
- for (var _len4 = arguments.length, params = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
125
- params[_key4 - 1] = arguments[_key4];
126
- }
127
-
128
166
  return YError.wrap.apply(YError, [err].concat(params));
129
167
  }; // In order to keep compatibility through major versions
130
168
  // we have to make kind of an cross major version instanceof
@@ -138,4 +176,6 @@ function _looksLikeAYErrorCode(str) {
138
176
  return /^([A-Z0-9_]+)$/.test(str);
139
177
  }
140
178
 
141
- module.exports = YError;
179
+ var _default = YError;
180
+ exports.default = _default;
181
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,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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 ADDED
@@ -0,0 +1,112 @@
1
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
+
3
+ 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); } }
4
+
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+
7
+ 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); }
8
+
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+
11
+ 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); }
12
+
13
+ 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); }
14
+
15
+ 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); }
16
+
17
+ 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; } }
18
+
19
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
20
+
21
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
+
23
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
+
25
+ import os from 'os';
26
+
27
+ let YError = function (_Error) {
28
+ _inherits(YError, _Error);
29
+
30
+ function YError(wrappedErrors, errorCode, ...params) {
31
+ var _this;
32
+
33
+ _classCallCheck(this, YError);
34
+
35
+ if (!(wrappedErrors instanceof Array)) {
36
+ params = ('undefined' === typeof errorCode ? [] : [errorCode]).concat(params);
37
+ errorCode = wrappedErrors;
38
+ wrappedErrors = [];
39
+ }
40
+
41
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(YError).call(this, errorCode));
42
+ _this.code = errorCode || 'E_UNEXPECTED';
43
+ _this.params = params;
44
+ _this.wrappedErrors = wrappedErrors;
45
+ _this.name = _this.toString();
46
+
47
+ if (Error.captureStackTrace) {
48
+ Error.captureStackTrace(_assertThisInitialized(_this), _this.constructor);
49
+ }
50
+
51
+ return _this;
52
+ }
53
+
54
+ _createClass(YError, [{
55
+ key: "toString",
56
+ value: function toString() {
57
+ return (this.wrappedErrors.length ? this.wrappedErrors[this.wrappedErrors.length - 1].stack + os.EOL : '') + this.constructor.name + ': ' + this.code + ' (' + this.params.join(', ') + ')';
58
+ }
59
+ }]);
60
+
61
+ return YError;
62
+ }(_wrapNativeSuper(Error));
63
+
64
+ YError.wrap = function yerrorWrap(err, errorCode, ...params) {
65
+ let yError = null;
66
+
67
+ const wrappedErrorIsACode = _looksLikeAYErrorCode(err.message);
68
+
69
+ const wrappedErrors = (err.wrappedErrors || []).concat(err);
70
+
71
+ if (!errorCode) {
72
+ if (wrappedErrorIsACode) {
73
+ errorCode = err.message;
74
+ } else {
75
+ errorCode = 'E_UNEXPECTED';
76
+ }
77
+ }
78
+
79
+ if (err.message && !wrappedErrorIsACode) {
80
+ params.push(err.message);
81
+ }
82
+
83
+ yError = new YError(wrappedErrors, errorCode, ...params);
84
+ return yError;
85
+ };
86
+
87
+ YError.cast = function yerrorCast(err, ...params) {
88
+ if (_looksLikeAYError(err)) {
89
+ return err;
90
+ }
91
+
92
+ return YError.wrap.apply(YError, [err].concat(params));
93
+ };
94
+
95
+ YError.bump = function yerrorBump(err, ...params) {
96
+ if (_looksLikeAYError(err)) {
97
+ return YError.wrap.apply(YError, [err, err.code].concat(err.params));
98
+ }
99
+
100
+ return YError.wrap.apply(YError, [err].concat(params));
101
+ };
102
+
103
+ function _looksLikeAYError(err) {
104
+ 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;
105
+ }
106
+
107
+ function _looksLikeAYErrorCode(str) {
108
+ return /^([A-Z0-9_]+)$/.test(str);
109
+ }
110
+
111
+ export default YError;
112
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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 _looksLikeAYErrorCode(str) {\n return /^([A-Z0-9_]+)$/.test(str);\n}\n\nexport default YError;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,EAAP,MAAe,IAAf;;IAOMC,M;;;EASJ,gBAAYC,aAAZ,EAA2BC,SAA3B,E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