@merkur/plugin-error 0.27.1 → 0.29.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/lib/index.cjs +143 -0
- package/lib/index.es5.js +1 -1
- package/lib/index.es9.cjs +143 -0
- package/lib/index.es9.mjs +143 -1
- package/lib/index.js +143 -0
- package/lib/index.mjs +143 -1
- package/lib/index.umd.js +1 -1
- package/package.json +8 -8
package/lib/index.cjs
CHANGED
|
@@ -4,6 +4,148 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@merkur/core');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Base class of custom error classes, extending the native `Error` class.
|
|
9
|
+
*
|
|
10
|
+
* This class has been introduced to fix the Babel-related issues with
|
|
11
|
+
* extending the native JavaScript (Error) classes.
|
|
12
|
+
*
|
|
13
|
+
* @abstract
|
|
14
|
+
* @class
|
|
15
|
+
* @extends Error
|
|
16
|
+
* @param {string} message The message describing the cause of the error.
|
|
17
|
+
* @param {boolean=} dropInternalStackFrames Whether or not the call stack
|
|
18
|
+
* frames referring to the constructors of the custom errors should be
|
|
19
|
+
* excluded from the stack of this error (just like the native platform
|
|
20
|
+
* call stack frames are dropped by the JS engine).
|
|
21
|
+
* This flag is enabled by default.
|
|
22
|
+
*/
|
|
23
|
+
function ExtensibleError(
|
|
24
|
+
message,
|
|
25
|
+
dropInternalStackFrames = true
|
|
26
|
+
) {
|
|
27
|
+
if (!(this instanceof ExtensibleError)) {
|
|
28
|
+
throw new TypeError('Cannot call a class as a function');
|
|
29
|
+
}
|
|
30
|
+
if (this.constructor === ExtensibleError) {
|
|
31
|
+
throw new TypeError(
|
|
32
|
+
'The ExtensibleError is an abstract class and ' +
|
|
33
|
+
'must be extended before it can be instantiated.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Error.call(this, message); // super-constructor call;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The name of this error, used in the generated stack trace.
|
|
41
|
+
*
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
this.name = this.constructor.name;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The message describing the cause of the error.
|
|
48
|
+
*
|
|
49
|
+
* @type {string}
|
|
50
|
+
*/
|
|
51
|
+
this.message = message;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Native error instance we use to generate the call stack. For some reason
|
|
55
|
+
* some browsers do not generate call stacks for instances of classes
|
|
56
|
+
* extending the native `Error` class, so we bypass this shortcoming this way.
|
|
57
|
+
*
|
|
58
|
+
* @type {Error}
|
|
59
|
+
*/
|
|
60
|
+
this._nativeError = new Error(message);
|
|
61
|
+
this._nativeError.name = this.name;
|
|
62
|
+
|
|
63
|
+
// improve compatibility with Gecko
|
|
64
|
+
if (this._nativeError.columnNumber) {
|
|
65
|
+
this.lineNumber = this._nativeError.lineNumber;
|
|
66
|
+
this.columnNumber = this._nativeError.columnNumber;
|
|
67
|
+
this.fileName = this._nativeError.fileName;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The internal cache of the generated stack. The cache is filled upon first
|
|
72
|
+
* access to the {@link ExtensibleError#stack} property.
|
|
73
|
+
*
|
|
74
|
+
* @type {?string}
|
|
75
|
+
*/
|
|
76
|
+
this._stack = null;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether or not the call stack frames referring to the constructors of
|
|
80
|
+
* the custom errors should be excluded from the stack of this error (just
|
|
81
|
+
* like the native platform call stack frames are dropped by the JS
|
|
82
|
+
* engine).
|
|
83
|
+
*
|
|
84
|
+
* @type {boolean}
|
|
85
|
+
*/
|
|
86
|
+
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
90
|
+
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The call stack captured at the moment of creation of this error. The
|
|
94
|
+
* formatting of the stack is browser-dependant.
|
|
95
|
+
*
|
|
96
|
+
* @var {string} ExtensibleError#stack
|
|
97
|
+
*/
|
|
98
|
+
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
99
|
+
configurable: true,
|
|
100
|
+
enumerable: false,
|
|
101
|
+
get: function () {
|
|
102
|
+
if (this._stack) {
|
|
103
|
+
return this._stack;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let stack = this._nativeError.stack;
|
|
107
|
+
if (typeof stack !== 'string') {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// drop the stack trace frames referring to the custom error
|
|
112
|
+
// constructors
|
|
113
|
+
if (this._dropInternalStackFrames) {
|
|
114
|
+
let stackLines = stack.split('\n');
|
|
115
|
+
|
|
116
|
+
let inheritanceDepth = 1;
|
|
117
|
+
let currentPrototype = Object.getPrototypeOf(this);
|
|
118
|
+
while (currentPrototype !== ExtensibleError.prototype) {
|
|
119
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
120
|
+
inheritanceDepth++;
|
|
121
|
+
}
|
|
122
|
+
stackLines.splice(1, inheritanceDepth);
|
|
123
|
+
|
|
124
|
+
this._stack = stackLines.join('\n');
|
|
125
|
+
} else {
|
|
126
|
+
this._stack = stack;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return this._stack;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
class GenericError extends ExtensibleError {
|
|
134
|
+
constructor(message, params) {
|
|
135
|
+
super(message);
|
|
136
|
+
const { status = 500, ...otherParams } = params;
|
|
137
|
+
|
|
138
|
+
this.name = 'Error';
|
|
139
|
+
this.status = status;
|
|
140
|
+
|
|
141
|
+
this._params = otherParams;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get params() {
|
|
145
|
+
return this._params;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
7
149
|
const DEV = 'development';
|
|
8
150
|
const ENV =
|
|
9
151
|
typeof process !== 'undefined' && process && process.env
|
|
@@ -134,6 +276,7 @@ async function renderContent(widget, method, properties) {
|
|
|
134
276
|
}
|
|
135
277
|
|
|
136
278
|
exports.ERROR_EVENTS = ERROR_EVENTS;
|
|
279
|
+
exports.GenericError = GenericError;
|
|
137
280
|
exports.errorPlugin = errorPlugin;
|
|
138
281
|
exports.renderContent = renderContent;
|
|
139
282
|
exports.setErrorInfo = setErrorInfo;
|
package/lib/index.es5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function r(r){return function(r){if(Array.isArray(r))return e(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(!r)return;if("string"==typeof r)return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);"Object"===n&&r.constructor&&(n=r.constructor.name);if("Map"===n||"Set"===n)return Array.from(r);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(r,t)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function t(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function n(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(e){o(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function o(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function s(r,e,t,n,o,s,u){try{var i=r[s](u),a=i.value}catch(r){return void t(r)}i.done?e(a):Promise.resolve(a).then(n,o)}function u(r){return function(){var e=this,t=arguments;return new Promise((function(n,o){var u=r.apply(e,t);function i(r){s(u,n,o,i,a,"next",r)}function a(r){s(u,n,o,i,a,"throw",r)}i(void 0)}))}}require("regenerator-runtime/runtime.js"),require("core-js/modules/es.object.define-property.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.array.for-each.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.object.define-properties.js"),require("core-js/modules/es.array.is-array.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.function.name.js"),Object.defineProperty(exports,"__esModule",{value:!0});var i=require("@merkur/core"),a="development",c="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:a,p={ERROR:"@merkur/plugin-error.error"};function l(r,e){return f.apply(this,arguments)}function f(){return f=u(regeneratorRuntime.mark((function r(e,t){var n,o,s,u,i=arguments;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n={},!e.error.status){r.next=3;break}return r.abrupt("return",n);case 3:for(r.prev=3,o=i.length,s=new Array(o>2?o-2:0),u=2;u<o;u++)s[u-2]=i[u];return r.next=7,t.apply(void 0,s);case 7:n=r.sent,r.next=15;break;case 10:r.prev=10,r.t0=r.catch(3),r.t0.status=r.t0.status||500,g(e,r.t0),v(e,r.t0);case 15:return r.abrupt("return",n);case 16:case"end":return r.stop()}}),r,null,[[3,10]])}))),f.apply(this,arguments)}function m(r,e){return d.apply(this,arguments)}function d(){return d=u(regeneratorRuntime.mark((function r(e,t){var o,s,u,i,a=arguments;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(o=a.length,s=new Array(o>2?o-2:0),u=2;u<o;u++)s[u-2]=a[u];return r.next=3,t.apply(void 0,s);case 3:return i=r.sent,r.abrupt("return",n({error:e.error},i));case 5:case"end":return r.stop()}}),r)}))),d.apply(this,arguments)}function j(r,e){return y.apply(this,arguments)}function y(){return y=u(regeneratorRuntime.mark((function r(e,t){var n,o,s,u=arguments;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=u.length,o=new Array(n>2?n-2:0),s=2;s<n;s++)o[s-2]=u[s];return r.abrupt("return",w(e,t,o));case 2:case"end":return r.stop()}}),r)}))),y.apply(this,arguments)}function b(r,e){return h.apply(this,arguments)}function h(){return h=u(regeneratorRuntime.mark((function r(e,t){var n,o,s,u=arguments;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=u.length,o=new Array(n>2?n-2:0),s=2;s<n;s++)o[s-2]=u[s];return r.abrupt("return",w(e,t,o));case 2:case"end":return r.stop()}}),r)}))),h.apply(this,arguments)}function g(r,e){r.error.status=e.status,r.error.message=e.message,c===a&&(r.error.stack=e.stack)}function v(r,e){r.emit(p.ERROR,{error:e})}function w(r,e,t){return k.apply(this,arguments)}function k(){return(k=u(regeneratorRuntime.mark((function e(t,n,o){var s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=null,!t.error.status){e.next=13;break}return e.prev=2,e.next=5,n.apply(void 0,r(o));case 5:case 16:return s=e.sent,e.abrupt("return",s);case 9:return e.prev=9,e.t0=e.catch(2),s="",e.abrupt("return",s);case 13:return e.prev=13,e.next=16,n.apply(void 0,r(o));case 20:return e.prev=20,e.t1=e.catch(13),e.t1.status=e.t1.status||500,g(t,e.t1),v(t,e.t1),e.abrupt("return",w(t,n,o));case 26:case"end":return e.stop()}}),e,null,[[2,9],[13,20]])})))).apply(this,arguments)}exports.ERROR_EVENTS=p,exports.errorPlugin=function(){return{setup:function(r){return u(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.error=r.error?r.error:{status:null,message:null},e.abrupt("return",r);case 2:case"end":return e.stop()}}),e)})))()},create:function(r){return u(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c!==a){e.next=5;break}if(r.$in.component){e.next=3;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-component");case 3:if(r.$in.eventEmitter){e.next=5;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-event-emitter");case 5:return i.hookMethod(r,"info",m),i.hookMethod(r,"load",l),i.hookMethod(r,"mount",j),i.hookMethod(r,"update",b),e.abrupt("return",r);case 10:case"end":return e.stop()}}),e)})))()}}},exports.renderContent=w,exports.setErrorInfo=g;
|
|
1
|
+
"use strict";function e(r){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(r)}var r=["status"];function t(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(!e)return;if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return n(e,r)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function s(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?o(Object(t),!0).forEach((function(r){u(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function u(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function i(e,r,t,n,o,s,u){try{var i=e[s](u),a=i.value}catch(e){return void t(e)}i.done?r(a):Promise.resolve(a).then(n,o)}function a(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var s=e.apply(r,t);function u(e){i(s,n,o,u,a,"next",e)}function a(e){i(s,n,o,u,a,"throw",e)}u(void 0)}))}}function c(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},s=Object.keys(e);for(n=0;n<s.length;n++)t=s[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)t=s[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function p(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function l(e,r){return l=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},l(e,r)}function f(e){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var t,n=y(e);if(r){var o=y(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return m(this,t)}}function m(r,t){if(t&&("object"===e(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(r)}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},y(e)}require("regenerator-runtime/runtime.js"),require("core-js/modules/es.object.define-property.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.object.create.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.string.split.js"),require("core-js/modules/es.object.get-prototype-of.js"),require("core-js/modules/es.array.splice.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.object.set-prototype-of.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.reflect.construct.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.index-of.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.array.for-each.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.object.define-properties.js"),require("core-js/modules/es.array.is-array.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.array.slice.js"),Object.defineProperty(exports,"__esModule",{value:!0});var b=require("@merkur/core");function j(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!(this instanceof j))throw new TypeError("Cannot call a class as a function");if(this.constructor===j)throw new TypeError("The ExtensibleError is an abstract class and must be extended before it can be instantiated.");Error.call(this,e),this.name=this.constructor.name,this.message=e,this._nativeError=new Error(e),this._nativeError.name=this.name,this._nativeError.columnNumber&&(this.lineNumber=this._nativeError.lineNumber,this.columnNumber=this._nativeError.columnNumber,this.fileName=this._nativeError.fileName),this._stack=null,this._dropInternalStackFrames=r}j.prototype=Object.create(Error.prototype),j.prototype.constructor=j,Object.defineProperty(j.prototype,"stack",{configurable:!0,enumerable:!1,get:function(){if(this._stack)return this._stack;var e=this._nativeError.stack;if("string"==typeof e){if(this._dropInternalStackFrames){for(var r=e.split("\n"),t=1,n=Object.getPrototypeOf(this);n!==j.prototype;)n=Object.getPrototypeOf(n),t++;r.splice(1,t),this._stack=r.join("\n")}else this._stack=e;return this._stack}}});var h=function(e){!function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&l(e,r)}(u,j);var t,n,o,s=f(u);function u(e,t){var n;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,u),n=s.call(this,e);var o=t.status,i=void 0===o?500:o,a=c(t,r);return n.name="Error",n.status=i,n._params=a,n}return t=u,(n=[{key:"params",get:function(){return this._params}}])&&p(t.prototype,n),o&&p(t,o),Object.defineProperty(t,"prototype",{writable:!1}),u}(),d="development",v="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:d,g={ERROR:"@merkur/plugin-error.error"};function w(e,r){return O.apply(this,arguments)}function O(){return O=a(regeneratorRuntime.mark((function e(r,t){var n,o,s,u,i=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n={},!r.error.status){e.next=3;break}return e.abrupt("return",n);case 3:for(e.prev=3,o=i.length,s=new Array(o>2?o-2:0),u=2;u<o;u++)s[u-2]=i[u];return e.next=7,t.apply(void 0,s);case 7:n=e.sent,e.next=15;break;case 10:e.prev=10,e.t0=e.catch(3),e.t0.status=e.t0.status||500,P(r,e.t0),S(r,e.t0);case 15:return e.abrupt("return",n);case 16:case"end":return e.stop()}}),e,null,[[3,10]])}))),O.apply(this,arguments)}function k(e,r){return E.apply(this,arguments)}function E(){return E=a(regeneratorRuntime.mark((function e(r,t){var n,o,u,i,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=a.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=a[u];return e.next=3,t.apply(void 0,o);case 3:return i=e.sent,e.abrupt("return",s({error:r.error},i));case 5:case"end":return e.stop()}}),e)}))),E.apply(this,arguments)}function x(e,r){return q.apply(this,arguments)}function q(){return q=a(regeneratorRuntime.mark((function e(r,t){var n,o,s,u=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=u.length,o=new Array(n>2?n-2:0),s=2;s<n;s++)o[s-2]=u[s];return e.abrupt("return",A(r,t,o));case 2:case"end":return e.stop()}}),e)}))),q.apply(this,arguments)}function R(e,r){return _.apply(this,arguments)}function _(){return _=a(regeneratorRuntime.mark((function e(r,t){var n,o,s,u=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=u.length,o=new Array(n>2?n-2:0),s=2;s<n;s++)o[s-2]=u[s];return e.abrupt("return",A(r,t,o));case 2:case"end":return e.stop()}}),e)}))),_.apply(this,arguments)}function P(e,r){e.error.status=r.status,e.error.message=r.message,v===d&&(e.error.stack=r.stack)}function S(e,r){e.emit(g.ERROR,{error:r})}function A(e,r,t){return N.apply(this,arguments)}function N(){return(N=a(regeneratorRuntime.mark((function e(r,n,o){var s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=null,!r.error.status){e.next=13;break}return e.prev=2,e.next=5,n.apply(void 0,t(o));case 5:case 16:return s=e.sent,e.abrupt("return",s);case 9:return e.prev=9,e.t0=e.catch(2),s="",e.abrupt("return",s);case 13:return e.prev=13,e.next=16,n.apply(void 0,t(o));case 20:return e.prev=20,e.t1=e.catch(13),e.t1.status=e.t1.status||500,P(r,e.t1),S(r,e.t1),e.abrupt("return",A(r,n,o));case 26:case"end":return e.stop()}}),e,null,[[2,9],[13,20]])})))).apply(this,arguments)}exports.ERROR_EVENTS=g,exports.GenericError=h,exports.errorPlugin=function(){return{setup:function(e){return a(regeneratorRuntime.mark((function r(){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e.error=e.error?e.error:{status:null,message:null},r.abrupt("return",e);case 2:case"end":return r.stop()}}),r)})))()},create:function(e){return a(regeneratorRuntime.mark((function r(){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(v!==d){r.next=5;break}if(e.$in.component){r.next=3;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-component");case 3:if(e.$in.eventEmitter){r.next=5;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-event-emitter");case 5:return b.hookMethod(e,"info",k),b.hookMethod(e,"load",w),b.hookMethod(e,"mount",x),b.hookMethod(e,"update",R),r.abrupt("return",e);case 10:case"end":return r.stop()}}),r)})))()}}},exports.renderContent=A,exports.setErrorInfo=P;
|
package/lib/index.es9.cjs
CHANGED
|
@@ -5,6 +5,148 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
5
5
|
});
|
|
6
6
|
|
|
7
7
|
var core = require('@merkur/core');
|
|
8
|
+
/**
|
|
9
|
+
* Base class of custom error classes, extending the native `Error` class.
|
|
10
|
+
*
|
|
11
|
+
* This class has been introduced to fix the Babel-related issues with
|
|
12
|
+
* extending the native JavaScript (Error) classes.
|
|
13
|
+
*
|
|
14
|
+
* @abstract
|
|
15
|
+
* @class
|
|
16
|
+
* @extends Error
|
|
17
|
+
* @param {string} message The message describing the cause of the error.
|
|
18
|
+
* @param {boolean=} dropInternalStackFrames Whether or not the call stack
|
|
19
|
+
* frames referring to the constructors of the custom errors should be
|
|
20
|
+
* excluded from the stack of this error (just like the native platform
|
|
21
|
+
* call stack frames are dropped by the JS engine).
|
|
22
|
+
* This flag is enabled by default.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
27
|
+
if (!(this instanceof ExtensibleError)) {
|
|
28
|
+
throw new TypeError('Cannot call a class as a function');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.constructor === ExtensibleError) {
|
|
32
|
+
throw new TypeError('The ExtensibleError is an abstract class and ' + 'must be extended before it can be instantiated.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Error.call(this, message); // super-constructor call;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The name of this error, used in the generated stack trace.
|
|
39
|
+
*
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
this.name = this.constructor.name;
|
|
44
|
+
/**
|
|
45
|
+
* The message describing the cause of the error.
|
|
46
|
+
*
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
this.message = message;
|
|
51
|
+
/**
|
|
52
|
+
* Native error instance we use to generate the call stack. For some reason
|
|
53
|
+
* some browsers do not generate call stacks for instances of classes
|
|
54
|
+
* extending the native `Error` class, so we bypass this shortcoming this way.
|
|
55
|
+
*
|
|
56
|
+
* @type {Error}
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
this._nativeError = new Error(message);
|
|
60
|
+
this._nativeError.name = this.name; // improve compatibility with Gecko
|
|
61
|
+
|
|
62
|
+
if (this._nativeError.columnNumber) {
|
|
63
|
+
this.lineNumber = this._nativeError.lineNumber;
|
|
64
|
+
this.columnNumber = this._nativeError.columnNumber;
|
|
65
|
+
this.fileName = this._nativeError.fileName;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The internal cache of the generated stack. The cache is filled upon first
|
|
69
|
+
* access to the {@link ExtensibleError#stack} property.
|
|
70
|
+
*
|
|
71
|
+
* @type {?string}
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
this._stack = null;
|
|
76
|
+
/**
|
|
77
|
+
* Whether or not the call stack frames referring to the constructors of
|
|
78
|
+
* the custom errors should be excluded from the stack of this error (just
|
|
79
|
+
* like the native platform call stack frames are dropped by the JS
|
|
80
|
+
* engine).
|
|
81
|
+
*
|
|
82
|
+
* @type {boolean}
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
89
|
+
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
90
|
+
/**
|
|
91
|
+
* The call stack captured at the moment of creation of this error. The
|
|
92
|
+
* formatting of the stack is browser-dependant.
|
|
93
|
+
*
|
|
94
|
+
* @var {string} ExtensibleError#stack
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
98
|
+
configurable: true,
|
|
99
|
+
enumerable: false,
|
|
100
|
+
get: function () {
|
|
101
|
+
if (this._stack) {
|
|
102
|
+
return this._stack;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let stack = this._nativeError.stack;
|
|
106
|
+
|
|
107
|
+
if (typeof stack !== 'string') {
|
|
108
|
+
return undefined;
|
|
109
|
+
} // drop the stack trace frames referring to the custom error
|
|
110
|
+
// constructors
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if (this._dropInternalStackFrames) {
|
|
114
|
+
let stackLines = stack.split('\n');
|
|
115
|
+
let inheritanceDepth = 1;
|
|
116
|
+
let currentPrototype = Object.getPrototypeOf(this);
|
|
117
|
+
|
|
118
|
+
while (currentPrototype !== ExtensibleError.prototype) {
|
|
119
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
120
|
+
inheritanceDepth++;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
stackLines.splice(1, inheritanceDepth);
|
|
124
|
+
this._stack = stackLines.join('\n');
|
|
125
|
+
} else {
|
|
126
|
+
this._stack = stack;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return this._stack;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
class GenericError extends ExtensibleError {
|
|
134
|
+
constructor(message, params) {
|
|
135
|
+
super(message);
|
|
136
|
+
const {
|
|
137
|
+
status = 500,
|
|
138
|
+
...otherParams
|
|
139
|
+
} = params;
|
|
140
|
+
this.name = 'Error';
|
|
141
|
+
this.status = status;
|
|
142
|
+
this._params = otherParams;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get params() {
|
|
146
|
+
return this._params;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
8
150
|
|
|
9
151
|
const DEV = 'development';
|
|
10
152
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
@@ -126,6 +268,7 @@ async function renderContent(widget, method, properties) {
|
|
|
126
268
|
}
|
|
127
269
|
|
|
128
270
|
exports.ERROR_EVENTS = ERROR_EVENTS;
|
|
271
|
+
exports.GenericError = GenericError;
|
|
129
272
|
exports.errorPlugin = errorPlugin;
|
|
130
273
|
exports.renderContent = renderContent;
|
|
131
274
|
exports.setErrorInfo = setErrorInfo;
|
package/lib/index.es9.mjs
CHANGED
|
@@ -1,4 +1,146 @@
|
|
|
1
1
|
import { hookMethod } from '@merkur/core';
|
|
2
|
+
/**
|
|
3
|
+
* Base class of custom error classes, extending the native `Error` class.
|
|
4
|
+
*
|
|
5
|
+
* This class has been introduced to fix the Babel-related issues with
|
|
6
|
+
* extending the native JavaScript (Error) classes.
|
|
7
|
+
*
|
|
8
|
+
* @abstract
|
|
9
|
+
* @class
|
|
10
|
+
* @extends Error
|
|
11
|
+
* @param {string} message The message describing the cause of the error.
|
|
12
|
+
* @param {boolean=} dropInternalStackFrames Whether or not the call stack
|
|
13
|
+
* frames referring to the constructors of the custom errors should be
|
|
14
|
+
* excluded from the stack of this error (just like the native platform
|
|
15
|
+
* call stack frames are dropped by the JS engine).
|
|
16
|
+
* This flag is enabled by default.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
20
|
+
if (!(this instanceof ExtensibleError)) {
|
|
21
|
+
throw new TypeError('Cannot call a class as a function');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (this.constructor === ExtensibleError) {
|
|
25
|
+
throw new TypeError('The ExtensibleError is an abstract class and ' + 'must be extended before it can be instantiated.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Error.call(this, message); // super-constructor call;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The name of this error, used in the generated stack trace.
|
|
32
|
+
*
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
this.name = this.constructor.name;
|
|
37
|
+
/**
|
|
38
|
+
* The message describing the cause of the error.
|
|
39
|
+
*
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
this.message = message;
|
|
44
|
+
/**
|
|
45
|
+
* Native error instance we use to generate the call stack. For some reason
|
|
46
|
+
* some browsers do not generate call stacks for instances of classes
|
|
47
|
+
* extending the native `Error` class, so we bypass this shortcoming this way.
|
|
48
|
+
*
|
|
49
|
+
* @type {Error}
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
this._nativeError = new Error(message);
|
|
53
|
+
this._nativeError.name = this.name; // improve compatibility with Gecko
|
|
54
|
+
|
|
55
|
+
if (this._nativeError.columnNumber) {
|
|
56
|
+
this.lineNumber = this._nativeError.lineNumber;
|
|
57
|
+
this.columnNumber = this._nativeError.columnNumber;
|
|
58
|
+
this.fileName = this._nativeError.fileName;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The internal cache of the generated stack. The cache is filled upon first
|
|
62
|
+
* access to the {@link ExtensibleError#stack} property.
|
|
63
|
+
*
|
|
64
|
+
* @type {?string}
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
this._stack = null;
|
|
69
|
+
/**
|
|
70
|
+
* Whether or not the call stack frames referring to the constructors of
|
|
71
|
+
* the custom errors should be excluded from the stack of this error (just
|
|
72
|
+
* like the native platform call stack frames are dropped by the JS
|
|
73
|
+
* engine).
|
|
74
|
+
*
|
|
75
|
+
* @type {boolean}
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
82
|
+
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
83
|
+
/**
|
|
84
|
+
* The call stack captured at the moment of creation of this error. The
|
|
85
|
+
* formatting of the stack is browser-dependant.
|
|
86
|
+
*
|
|
87
|
+
* @var {string} ExtensibleError#stack
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
91
|
+
configurable: true,
|
|
92
|
+
enumerable: false,
|
|
93
|
+
get: function () {
|
|
94
|
+
if (this._stack) {
|
|
95
|
+
return this._stack;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let stack = this._nativeError.stack;
|
|
99
|
+
|
|
100
|
+
if (typeof stack !== 'string') {
|
|
101
|
+
return undefined;
|
|
102
|
+
} // drop the stack trace frames referring to the custom error
|
|
103
|
+
// constructors
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if (this._dropInternalStackFrames) {
|
|
107
|
+
let stackLines = stack.split('\n');
|
|
108
|
+
let inheritanceDepth = 1;
|
|
109
|
+
let currentPrototype = Object.getPrototypeOf(this);
|
|
110
|
+
|
|
111
|
+
while (currentPrototype !== ExtensibleError.prototype) {
|
|
112
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
113
|
+
inheritanceDepth++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
stackLines.splice(1, inheritanceDepth);
|
|
117
|
+
this._stack = stackLines.join('\n');
|
|
118
|
+
} else {
|
|
119
|
+
this._stack = stack;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return this._stack;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
class GenericError extends ExtensibleError {
|
|
127
|
+
constructor(message, params) {
|
|
128
|
+
super(message);
|
|
129
|
+
const {
|
|
130
|
+
status = 500,
|
|
131
|
+
...otherParams
|
|
132
|
+
} = params;
|
|
133
|
+
this.name = 'Error';
|
|
134
|
+
this.status = status;
|
|
135
|
+
this._params = otherParams;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get params() {
|
|
139
|
+
return this._params;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
2
144
|
const DEV = 'development';
|
|
3
145
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
4
146
|
const ERROR_EVENTS = {
|
|
@@ -118,4 +260,4 @@ async function renderContent(widget, method, properties) {
|
|
|
118
260
|
}
|
|
119
261
|
}
|
|
120
262
|
|
|
121
|
-
export { ERROR_EVENTS, errorPlugin, renderContent, setErrorInfo };
|
|
263
|
+
export { ERROR_EVENTS, GenericError, errorPlugin, renderContent, setErrorInfo };
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,148 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@merkur/core');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Base class of custom error classes, extending the native `Error` class.
|
|
9
|
+
*
|
|
10
|
+
* This class has been introduced to fix the Babel-related issues with
|
|
11
|
+
* extending the native JavaScript (Error) classes.
|
|
12
|
+
*
|
|
13
|
+
* @abstract
|
|
14
|
+
* @class
|
|
15
|
+
* @extends Error
|
|
16
|
+
* @param {string} message The message describing the cause of the error.
|
|
17
|
+
* @param {boolean=} dropInternalStackFrames Whether or not the call stack
|
|
18
|
+
* frames referring to the constructors of the custom errors should be
|
|
19
|
+
* excluded from the stack of this error (just like the native platform
|
|
20
|
+
* call stack frames are dropped by the JS engine).
|
|
21
|
+
* This flag is enabled by default.
|
|
22
|
+
*/
|
|
23
|
+
function ExtensibleError(
|
|
24
|
+
message,
|
|
25
|
+
dropInternalStackFrames = true
|
|
26
|
+
) {
|
|
27
|
+
if (!(this instanceof ExtensibleError)) {
|
|
28
|
+
throw new TypeError('Cannot call a class as a function');
|
|
29
|
+
}
|
|
30
|
+
if (this.constructor === ExtensibleError) {
|
|
31
|
+
throw new TypeError(
|
|
32
|
+
'The ExtensibleError is an abstract class and ' +
|
|
33
|
+
'must be extended before it can be instantiated.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Error.call(this, message); // super-constructor call;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The name of this error, used in the generated stack trace.
|
|
41
|
+
*
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
this.name = this.constructor.name;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The message describing the cause of the error.
|
|
48
|
+
*
|
|
49
|
+
* @type {string}
|
|
50
|
+
*/
|
|
51
|
+
this.message = message;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Native error instance we use to generate the call stack. For some reason
|
|
55
|
+
* some browsers do not generate call stacks for instances of classes
|
|
56
|
+
* extending the native `Error` class, so we bypass this shortcoming this way.
|
|
57
|
+
*
|
|
58
|
+
* @type {Error}
|
|
59
|
+
*/
|
|
60
|
+
this._nativeError = new Error(message);
|
|
61
|
+
this._nativeError.name = this.name;
|
|
62
|
+
|
|
63
|
+
// improve compatibility with Gecko
|
|
64
|
+
if (this._nativeError.columnNumber) {
|
|
65
|
+
this.lineNumber = this._nativeError.lineNumber;
|
|
66
|
+
this.columnNumber = this._nativeError.columnNumber;
|
|
67
|
+
this.fileName = this._nativeError.fileName;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The internal cache of the generated stack. The cache is filled upon first
|
|
72
|
+
* access to the {@link ExtensibleError#stack} property.
|
|
73
|
+
*
|
|
74
|
+
* @type {?string}
|
|
75
|
+
*/
|
|
76
|
+
this._stack = null;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether or not the call stack frames referring to the constructors of
|
|
80
|
+
* the custom errors should be excluded from the stack of this error (just
|
|
81
|
+
* like the native platform call stack frames are dropped by the JS
|
|
82
|
+
* engine).
|
|
83
|
+
*
|
|
84
|
+
* @type {boolean}
|
|
85
|
+
*/
|
|
86
|
+
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
90
|
+
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The call stack captured at the moment of creation of this error. The
|
|
94
|
+
* formatting of the stack is browser-dependant.
|
|
95
|
+
*
|
|
96
|
+
* @var {string} ExtensibleError#stack
|
|
97
|
+
*/
|
|
98
|
+
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
99
|
+
configurable: true,
|
|
100
|
+
enumerable: false,
|
|
101
|
+
get: function () {
|
|
102
|
+
if (this._stack) {
|
|
103
|
+
return this._stack;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let stack = this._nativeError.stack;
|
|
107
|
+
if (typeof stack !== 'string') {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// drop the stack trace frames referring to the custom error
|
|
112
|
+
// constructors
|
|
113
|
+
if (this._dropInternalStackFrames) {
|
|
114
|
+
let stackLines = stack.split('\n');
|
|
115
|
+
|
|
116
|
+
let inheritanceDepth = 1;
|
|
117
|
+
let currentPrototype = Object.getPrototypeOf(this);
|
|
118
|
+
while (currentPrototype !== ExtensibleError.prototype) {
|
|
119
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
120
|
+
inheritanceDepth++;
|
|
121
|
+
}
|
|
122
|
+
stackLines.splice(1, inheritanceDepth);
|
|
123
|
+
|
|
124
|
+
this._stack = stackLines.join('\n');
|
|
125
|
+
} else {
|
|
126
|
+
this._stack = stack;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return this._stack;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
class GenericError extends ExtensibleError {
|
|
134
|
+
constructor(message, params) {
|
|
135
|
+
super(message);
|
|
136
|
+
const { status = 500, ...otherParams } = params;
|
|
137
|
+
|
|
138
|
+
this.name = 'Error';
|
|
139
|
+
this.status = status;
|
|
140
|
+
|
|
141
|
+
this._params = otherParams;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get params() {
|
|
145
|
+
return this._params;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
7
149
|
const DEV = 'development';
|
|
8
150
|
const ENV =
|
|
9
151
|
typeof process !== 'undefined' && process && process.env
|
|
@@ -134,6 +276,7 @@ async function renderContent(widget, method, properties) {
|
|
|
134
276
|
}
|
|
135
277
|
|
|
136
278
|
exports.ERROR_EVENTS = ERROR_EVENTS;
|
|
279
|
+
exports.GenericError = GenericError;
|
|
137
280
|
exports.errorPlugin = errorPlugin;
|
|
138
281
|
exports.renderContent = renderContent;
|
|
139
282
|
exports.setErrorInfo = setErrorInfo;
|
package/lib/index.mjs
CHANGED
|
@@ -1,5 +1,147 @@
|
|
|
1
1
|
import { hookMethod } from '@merkur/core';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Base class of custom error classes, extending the native `Error` class.
|
|
5
|
+
*
|
|
6
|
+
* This class has been introduced to fix the Babel-related issues with
|
|
7
|
+
* extending the native JavaScript (Error) classes.
|
|
8
|
+
*
|
|
9
|
+
* @abstract
|
|
10
|
+
* @class
|
|
11
|
+
* @extends Error
|
|
12
|
+
* @param {string} message The message describing the cause of the error.
|
|
13
|
+
* @param {boolean=} dropInternalStackFrames Whether or not the call stack
|
|
14
|
+
* frames referring to the constructors of the custom errors should be
|
|
15
|
+
* excluded from the stack of this error (just like the native platform
|
|
16
|
+
* call stack frames are dropped by the JS engine).
|
|
17
|
+
* This flag is enabled by default.
|
|
18
|
+
*/
|
|
19
|
+
function ExtensibleError(
|
|
20
|
+
message,
|
|
21
|
+
dropInternalStackFrames = true
|
|
22
|
+
) {
|
|
23
|
+
if (!(this instanceof ExtensibleError)) {
|
|
24
|
+
throw new TypeError('Cannot call a class as a function');
|
|
25
|
+
}
|
|
26
|
+
if (this.constructor === ExtensibleError) {
|
|
27
|
+
throw new TypeError(
|
|
28
|
+
'The ExtensibleError is an abstract class and ' +
|
|
29
|
+
'must be extended before it can be instantiated.'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Error.call(this, message); // super-constructor call;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The name of this error, used in the generated stack trace.
|
|
37
|
+
*
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
this.name = this.constructor.name;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The message describing the cause of the error.
|
|
44
|
+
*
|
|
45
|
+
* @type {string}
|
|
46
|
+
*/
|
|
47
|
+
this.message = message;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Native error instance we use to generate the call stack. For some reason
|
|
51
|
+
* some browsers do not generate call stacks for instances of classes
|
|
52
|
+
* extending the native `Error` class, so we bypass this shortcoming this way.
|
|
53
|
+
*
|
|
54
|
+
* @type {Error}
|
|
55
|
+
*/
|
|
56
|
+
this._nativeError = new Error(message);
|
|
57
|
+
this._nativeError.name = this.name;
|
|
58
|
+
|
|
59
|
+
// improve compatibility with Gecko
|
|
60
|
+
if (this._nativeError.columnNumber) {
|
|
61
|
+
this.lineNumber = this._nativeError.lineNumber;
|
|
62
|
+
this.columnNumber = this._nativeError.columnNumber;
|
|
63
|
+
this.fileName = this._nativeError.fileName;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The internal cache of the generated stack. The cache is filled upon first
|
|
68
|
+
* access to the {@link ExtensibleError#stack} property.
|
|
69
|
+
*
|
|
70
|
+
* @type {?string}
|
|
71
|
+
*/
|
|
72
|
+
this._stack = null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether or not the call stack frames referring to the constructors of
|
|
76
|
+
* the custom errors should be excluded from the stack of this error (just
|
|
77
|
+
* like the native platform call stack frames are dropped by the JS
|
|
78
|
+
* engine).
|
|
79
|
+
*
|
|
80
|
+
* @type {boolean}
|
|
81
|
+
*/
|
|
82
|
+
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
86
|
+
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The call stack captured at the moment of creation of this error. The
|
|
90
|
+
* formatting of the stack is browser-dependant.
|
|
91
|
+
*
|
|
92
|
+
* @var {string} ExtensibleError#stack
|
|
93
|
+
*/
|
|
94
|
+
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
95
|
+
configurable: true,
|
|
96
|
+
enumerable: false,
|
|
97
|
+
get: function () {
|
|
98
|
+
if (this._stack) {
|
|
99
|
+
return this._stack;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let stack = this._nativeError.stack;
|
|
103
|
+
if (typeof stack !== 'string') {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// drop the stack trace frames referring to the custom error
|
|
108
|
+
// constructors
|
|
109
|
+
if (this._dropInternalStackFrames) {
|
|
110
|
+
let stackLines = stack.split('\n');
|
|
111
|
+
|
|
112
|
+
let inheritanceDepth = 1;
|
|
113
|
+
let currentPrototype = Object.getPrototypeOf(this);
|
|
114
|
+
while (currentPrototype !== ExtensibleError.prototype) {
|
|
115
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
116
|
+
inheritanceDepth++;
|
|
117
|
+
}
|
|
118
|
+
stackLines.splice(1, inheritanceDepth);
|
|
119
|
+
|
|
120
|
+
this._stack = stackLines.join('\n');
|
|
121
|
+
} else {
|
|
122
|
+
this._stack = stack;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return this._stack;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
class GenericError extends ExtensibleError {
|
|
130
|
+
constructor(message, params) {
|
|
131
|
+
super(message);
|
|
132
|
+
const { status = 500, ...otherParams } = params;
|
|
133
|
+
|
|
134
|
+
this.name = 'Error';
|
|
135
|
+
this.status = status;
|
|
136
|
+
|
|
137
|
+
this._params = otherParams;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get params() {
|
|
141
|
+
return this._params;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
3
145
|
const DEV = 'development';
|
|
4
146
|
const ENV =
|
|
5
147
|
typeof process !== 'undefined' && process && process.env
|
|
@@ -129,4 +271,4 @@ async function renderContent(widget, method, properties) {
|
|
|
129
271
|
}
|
|
130
272
|
}
|
|
131
273
|
|
|
132
|
-
export { ERROR_EVENTS, errorPlugin, renderContent, setErrorInfo };
|
|
274
|
+
export { ERROR_EVENTS, GenericError, errorPlugin, renderContent, setErrorInfo };
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(r,
|
|
1
|
+
function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},r(t)}!function(r,t){if("function"==typeof define&&define.amd)define("@merkur/plugin-error",["exports","@merkur/core"],t);else if("undefined"!=typeof exports)t(exports,require("@merkur/core"));else{var e={exports:{}};t(e.exports,r.Merkur.Core),r.Merkur=r.Merkur||{},r.Merkur.Plugin=r.Merkur.Plugin||{},r.Merkur.Plugin.Error=e.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,e){Object.defineProperty(t,"__esModule",{value:!0}),t.GenericError=t.ERROR_EVENTS=void 0,t.errorPlugin=function(){return{setup:function(r){return f((function*(){return r.error=r.error?r.error:{status:null,message:null},r}))()},create:function(r){return f((function*(){if(g===O){if(!r.$in.component)throw new Error("You must install missing plugin: npm i @merkur/plugin-component");if(!r.$in.eventEmitter)throw new Error("You must install missing plugin: npm i @merkur/plugin-event-emitter")}return(0,e.hookMethod)(r,"info",k),(0,e.hookMethod)(r,"load",w),(0,e.hookMethod)(r,"mount",P),(0,e.hookMethod)(r,"update",R),r}))()}}},t.renderContent=N,t.setErrorInfo=M;var n=["status"];function o(r){return function(r){if(Array.isArray(r))return i(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(!r)return;if("string"==typeof r)return i(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);"Object"===e&&r.constructor&&(e=r.constructor.name);if("Map"===e||"Set"===e)return Array.from(r);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return i(r,t)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function u(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function c(r){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?u(Object(e),!0).forEach((function(t){a(r,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):u(Object(e)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))}))}return r}function a(r,t,e){return t in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function s(r,t,e,n,o,i,u){try{var c=r[i](u),a=c.value}catch(r){return void e(r)}c.done?t(a):Promise.resolve(a).then(n,o)}function f(r){return function(){var t=this,e=arguments;return new Promise((function(n,o){var i=r.apply(t,e);function u(r){s(i,n,o,u,c,"next",r)}function c(r){s(i,n,o,u,c,"throw",r)}u(void 0)}))}}function l(r,t){if(null==r)return{};var e,n,o=function(r,t){if(null==r)return{};var e,n,o={},i=Object.keys(r);for(n=0;n<i.length;n++)e=i[n],t.indexOf(e)>=0||(o[e]=r[e]);return o}(r,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);for(n=0;n<i.length;n++)e=i[n],t.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}function p(r,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function y(r,t){return y=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r},y(r,t)}function h(r){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(r){return!1}}();return function(){var e,n=m(r);if(t){var o=m(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return b(this,e)}}function b(t,e){if(e&&("object"===r(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}(t)}function m(r){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},m(r)}function d(r){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!(this instanceof d))throw new TypeError("Cannot call a class as a function");if(this.constructor===d)throw new TypeError("The ExtensibleError is an abstract class and must be extended before it can be instantiated.");Error.call(this,r),this.name=this.constructor.name,this.message=r,this._nativeError=new Error(r),this._nativeError.name=this.name,this._nativeError.columnNumber&&(this.lineNumber=this._nativeError.lineNumber,this.columnNumber=this._nativeError.columnNumber,this.fileName=this._nativeError.fileName),this._stack=null,this._dropInternalStackFrames=t}d.prototype=Object.create(Error.prototype),d.prototype.constructor=d,Object.defineProperty(d.prototype,"stack",{configurable:!0,enumerable:!1,get:function(){if(this._stack)return this._stack;var r=this._nativeError.stack;if("string"==typeof r){if(this._dropInternalStackFrames){for(var t=r.split("\n"),e=1,n=Object.getPrototypeOf(this);n!==d.prototype;)n=Object.getPrototypeOf(n),e++;t.splice(1,e),this._stack=t.join("\n")}else this._stack=r;return this._stack}}});var v=function(r){!function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&y(r,t)}(u,r);var t,e,o,i=h(u);function u(r,t){var e;!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),e=i.call(this,r);var o=t.status,c=void 0===o?500:o,a=l(t,n);return e.name="Error",e.status=c,e._params=a,e}return t=u,(e=[{key:"params",get:function(){return this._params}}])&&p(t.prototype,e),o&&p(t,o),Object.defineProperty(t,"prototype",{writable:!1}),u}(d);t.GenericError=v;var O="development",g="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:O,E={ERROR:"@merkur/plugin-error.error"};function w(r,t){return j.apply(this,arguments)}function j(){return j=f((function*(r,t){var e={};if(r.error.status)return e;try{for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];e=yield t.apply(void 0,o)}catch(t){t.status=t.status||500,M(r,t),A(r,t)}return e})),j.apply(this,arguments)}function k(r,t){return _.apply(this,arguments)}function _(){return _=f((function*(r,t){for(var e=arguments.length,n=new Array(e>2?e-2:0),o=2;o<e;o++)n[o-2]=arguments[o];var i=yield t.apply(void 0,n);return c({error:r.error},i)})),_.apply(this,arguments)}function P(r,t){return S.apply(this,arguments)}function S(){return S=f((function*(r,t){for(var e=arguments.length,n=new Array(e>2?e-2:0),o=2;o<e;o++)n[o-2]=arguments[o];return N(r,t,n)})),S.apply(this,arguments)}function R(r,t){return x.apply(this,arguments)}function x(){return x=f((function*(r,t){for(var e=arguments.length,n=new Array(e>2?e-2:0),o=2;o<e;o++)n[o-2]=arguments[o];return N(r,t,n)})),x.apply(this,arguments)}function M(r,t){r.error.status=t.status,r.error.message=t.message,g===O&&(r.error.stack=t.stack)}function A(r,t){r.emit(E.ERROR,{error:t})}function N(r,t,e){return T.apply(this,arguments)}function T(){return(T=f((function*(r,t,e){if(r.error.status)try{return yield t.apply(void 0,o(e))}catch(r){return""}try{return yield t.apply(void 0,o(e))}catch(n){return n.status=n.status||500,M(r,n),A(r,n),N(r,t,e)}}))).apply(this,arguments)}t.ERROR_EVENTS=E}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/plugin-error",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Merkur plugin for error handling.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"preversion": "npm test",
|
|
28
28
|
"test": "../../node_modules/.bin/jest --no-watchman -c ./jest.config.js",
|
|
29
|
-
"test:es:version": "../../node_modules/.bin/es-check es5 ./lib/index.es5.js && ../../node_modules/.bin/es-check
|
|
29
|
+
"test:es:version": "../../node_modules/.bin/es-check es5 ./lib/index.es5.js && ../../node_modules/.bin/es-check es11 ./lib/index.mjs --module && ../../node_modules/.bin/es-check es9 ./lib/index.es9.mjs --module && ../../node_modules/.bin/es-check es9 ./lib/index.es9.cjs --module",
|
|
30
30
|
"build": "node_modules/.bin/rollup -c",
|
|
31
31
|
"prepare": "npm run build"
|
|
32
32
|
},
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://merkur.js.org/",
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@merkur/core": "^0.
|
|
54
|
-
"@merkur/plugin-component": "^0.
|
|
55
|
-
"rollup": "^2.
|
|
53
|
+
"@merkur/core": "^0.29.0",
|
|
54
|
+
"@merkur/plugin-component": "^0.29.0",
|
|
55
|
+
"rollup": "^2.70.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@merkur/core": "
|
|
59
|
-
"@merkur/plugin-component": "
|
|
58
|
+
"@merkur/core": "*",
|
|
59
|
+
"@merkur/plugin-component": "*"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "ddc13f0ef4d1b18a02461011dae5df49d55f03a6"
|
|
62
62
|
}
|