@merkur/plugin-error 0.29.3 → 0.31.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.es5.js +1 -1
- package/lib/index.es9.cjs +17 -46
- package/lib/index.es9.mjs +17 -44
- package/lib/index.umd.js +1 -1
- package/package.json +4 -4
package/lib/index.es5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";function r(e){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(e)}var e=["status"];function t(r){return function(r){if(Array.isArray(r))return n(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,e){if(!r)return;if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);"Object"===t&&r.constructor&&(t=r.constructor.name);if("Map"===t||"Set"===t)return Array.from(r);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return n(r,e)}(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 n(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 o(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 i(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?o(Object(t),!0).forEach((function(e){s(r,e,t[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(t,e))}))}return r}function s(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function u(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */u=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,o=Object.defineProperty||function(r,e,t){r[e]=t.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{l({},"")}catch(r){l=function(r,e,t){return r[e]=t}}function f(r,e,t,n){var i=e&&e.prototype instanceof y?e:y,s=Object.create(i.prototype),u=new q(n||[]);return o(s,"_invoke",{value:x(r,t,u)}),s}function p(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(r){return{type:"throw",arg:r}}}e.wrap=f;var h={};function y(){}function d(){}function m(){}var v={};l(v,s,(function(){return this}));var b=Object.getPrototypeOf,j=b&&b(b(P([])));j&&j!==t&&n.call(j,s)&&(v=j);var g=m.prototype=y.prototype=Object.create(v);function w(r){["next","throw","return"].forEach((function(e){l(r,e,(function(r){return this._invoke(e,r)}))}))}function O(e,t){function i(o,s,u,a){var c=p(e[o],e,s);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==r(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(r){i("next",r,u,a)}),(function(r){i("throw",r,u,a)})):t.resolve(f).then((function(r){l.value=r,u(l)}),(function(r){return i("throw",r,u,a)}))}a(c.arg)}var s;o(this,"_invoke",{value:function(r,e){function n(){return new t((function(t,n){i(r,e,t,n)}))}return s=s?s.then(n,n):n()}})}function x(r,e,t){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(t.method=o,t.arg=i;;){var s=t.delegate;if(s){var u=E(s,t);if(u){if(u===h)continue;return u}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var a=p(r,e,t);if("normal"===a.type){if(n=t.done?"completed":"suspendedYield",a.arg===h)continue;return{value:a.arg,done:t.done}}"throw"===a.type&&(n="completed",t.method="throw",t.arg=a.arg)}}}function E(r,e){var t=r.iterator[e.method];if(void 0===t){if(e.delegate=null,"throw"===e.method){if(r.iterator.return&&(e.method="return",e.arg=void 0,E(r,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=p(t,r.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[r.resultName]=o.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function k(r){var e={tryLoc:r[0]};1 in r&&(e.catchLoc=r[1]),2 in r&&(e.finallyLoc=r[2],e.afterLoc=r[3]),this.tryEntries.push(e)}function _(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function q(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(k,this),this.reset(!0)}function P(r){if(r){var e=r[s];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var t=-1,o=function e(){for(;++t<r.length;)if(n.call(r,t))return e.value=r[t],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=m,o(g,"constructor",{value:m,configurable:!0}),o(m,"constructor",{value:d,configurable:!0}),d.displayName=l(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(r){var e="function"==typeof r&&r.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,m):(r.__proto__=m,l(r,c,"GeneratorFunction")),r.prototype=Object.create(g),r},e.awrap=function(r){return{__await:r}},w(O.prototype),l(O.prototype,a,(function(){return this})),e.AsyncIterator=O,e.async=function(r,t,n,o,i){void 0===i&&(i=Promise);var s=new O(f(r,t,n,o),i);return e.isGeneratorFunction(t)?s:s.next().then((function(r){return r.done?r.value:s.next()}))},w(g),l(g,c,"Generator"),l(g,s,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),e.keys=function(r){var e=Object(r),t=[];for(var n in e)t.push(n);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=P,q.prototype={constructor:q,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var r=this.tryEntries[0].completion;if("throw"===r.type)throw r.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function t(t,n){return s.type="throw",s.arg=r,e.next=t,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return t("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),a=n.call(i,"finallyLoc");if(u&&a){if(this.prev<i.catchLoc)return t(i.catchLoc,!0);if(this.prev<i.finallyLoc)return t(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return t(i.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return t(i.finallyLoc)}}}},abrupt:function(r,e){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=r,s.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(s)},complete:function(r,e){if("throw"===r.type)throw r.arg;return"break"===r.type||"continue"===r.type?this.next=r.arg:"return"===r.type?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):"normal"===r.type&&e&&(this.next=e),h},finish:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===r)return this.complete(t.completion,t.afterLoc),_(t),h}},catch:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===r){var n=t.completion;if("throw"===n.type){var o=n.arg;_(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:P(r),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),h}},e}function a(r,e,t,n,o,i,s){try{var u=r[i](s),a=u.value}catch(r){return void t(r)}u.done?e(a):Promise.resolve(a).then(n,o)}function c(r){return function(){var e=this,t=arguments;return new Promise((function(n,o){var i=r.apply(e,t);function s(r){a(i,n,o,s,u,"next",r)}function u(r){a(i,n,o,s,u,"throw",r)}s(void 0)}))}}function l(r,e){if(null==r)return{};var t,n,o=function(r,e){if(null==r)return{};var t,n,o={},i=Object.keys(r);for(n=0;n<i.length;n++)t=i[n],e.indexOf(t)>=0||(o[t]=r[t]);return o}(r,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);for(n=0;n<i.length;n++)t=i[n],e.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(r,t)&&(o[t]=r[t])}return o}function f(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function p(r,e){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},p(r,e)}function h(r){var e=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 t,n=d(r);if(e){var o=d(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return y(this,t)}}function y(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)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}(e)}function d(r){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},d(r)}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.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.function.bind.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.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.symbol.async-iterator.js"),require("core-js/modules/es.symbol.to-string-tag.js"),require("core-js/modules/es.json.to-string-tag.js"),require("core-js/modules/es.math.to-string-tag.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.array.reverse.js"),require("core-js/modules/es.array.slice.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.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.array.from.js"),require("core-js/modules/es.regexp.exec.js"),Object.defineProperty(exports,"__esModule",{value:!0});var m=require("@merkur/core");function v(r){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!(this instanceof v))throw new TypeError("Cannot call a class as a function");if(this.constructor===v)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=e}v.prototype=Object.create(Error.prototype),v.prototype.constructor=v,Object.defineProperty(v.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 e=r.split("\n"),t=1,n=Object.getPrototypeOf(this);n!==v.prototype;)n=Object.getPrototypeOf(n),t++;e.splice(1,t),this._stack=e.join("\n")}else this._stack=r;return this._stack}}});var b=function(r){!function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&p(r,e)}(s,v);var t,n,o,i=h(s);function s(r,t){var n;!function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,s),n=i.call(this,r);var o=t.status,u=void 0===o?500:o,a=l(t,e);return n.name="Error",n.status=u,n._params=a,n}return t=s,(n=[{key:"params",get:function(){return this._params}}])&&f(t.prototype,n),o&&f(t,o),Object.defineProperty(t,"prototype",{writable:!1}),s}(),j="development",g="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:j,w={ERROR:"@merkur/plugin-error.error"};function O(r,e){return x.apply(this,arguments)}function x(){return x=c(u().mark((function r(e,t){var n,o,i,s,a=arguments;return u().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=a.length,i=new Array(o>2?o-2:0),s=2;s<o;s++)i[s-2]=a[s];return r.next=7,t.apply(void 0,i);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,S(e,r.t0),N(e,r.t0);case 15:return r.abrupt("return",n);case 16:case"end":return r.stop()}}),r,null,[[3,10]])}))),x.apply(this,arguments)}function E(r,e){return k.apply(this,arguments)}function k(){return k=c(u().mark((function r(e,t){var n,o,s,a,c=arguments;return u().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=c.length,o=new Array(n>2?n-2:0),s=2;s<n;s++)o[s-2]=c[s];return r.next=3,t.apply(void 0,o);case 3:return a=r.sent,r.abrupt("return",i({error:e.error},a));case 5:case"end":return r.stop()}}),r)}))),k.apply(this,arguments)}function _(r,e){return q.apply(this,arguments)}function q(){return q=c(u().mark((function r(e,t){var n,o,i,s=arguments;return u().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=s.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=s[i];return r.abrupt("return",R(e,t,o));case 2:case"end":return r.stop()}}),r)}))),q.apply(this,arguments)}function P(r,e){return L.apply(this,arguments)}function L(){return L=c(u().mark((function r(e,t){var n,o,i,s=arguments;return u().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=s.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=s[i];return r.abrupt("return",R(e,t,o));case 2:case"end":return r.stop()}}),r)}))),L.apply(this,arguments)}function S(r,e){r.error.status=e.status,r.error.message=e.message,g===j&&(r.error.stack=e.stack)}function N(r,e){r.emit(w.ERROR,{error:e})}function R(r,e,t){return A.apply(this,arguments)}function A(){return(A=c(u().mark((function r(e,n,o){var i;return u().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(i=null,!e.error.status){r.next=13;break}return r.prev=2,r.next=5,n.apply(void 0,t(o));case 5:case 16:return i=r.sent,r.abrupt("return",i);case 9:return r.prev=9,r.t0=r.catch(2),i="",r.abrupt("return",i);case 13:return r.prev=13,r.next=16,n.apply(void 0,t(o));case 20:return r.prev=20,r.t1=r.catch(13),r.t1.status=r.t1.status||500,S(e,r.t1),N(e,r.t1),r.abrupt("return",R(e,n,o));case 26:case"end":return r.stop()}}),r,null,[[2,9],[13,20]])})))).apply(this,arguments)}exports.ERROR_EVENTS=w,exports.GenericError=b,exports.errorPlugin=function(){return{setup:function(r){return c(u().mark((function e(){return u().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 c(u().mark((function e(){return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(g!==j){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 m.hookMethod(r,"info",E),m.hookMethod(r,"load",O),m.hookMethod(r,"mount",_),m.hookMethod(r,"update",P),e.abrupt("return",r);case 10:case"end":return e.stop()}}),e)})))()}}},exports.renderContent=R,exports.setErrorInfo=S;
|
package/lib/index.es9.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var core = require('@merkur/core');
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Base class of custom error classes, extending the native `Error` class.
|
|
10
10
|
*
|
|
@@ -21,17 +21,13 @@ var core = require('@merkur/core');
|
|
|
21
21
|
* call stack frames are dropped by the JS engine).
|
|
22
22
|
* This flag is enabled by default.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
27
25
|
if (!(this instanceof ExtensibleError)) {
|
|
28
26
|
throw new TypeError('Cannot call a class as a function');
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
if (this.constructor === ExtensibleError) {
|
|
32
29
|
throw new TypeError('The ExtensibleError is an abstract class and ' + 'must be extended before it can be instantiated.');
|
|
33
30
|
}
|
|
34
|
-
|
|
35
31
|
Error.call(this, message); // super-constructor call;
|
|
36
32
|
|
|
37
33
|
/**
|
|
@@ -39,15 +35,15 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
39
35
|
*
|
|
40
36
|
* @type {string}
|
|
41
37
|
*/
|
|
42
|
-
|
|
43
38
|
this.name = this.constructor.name;
|
|
39
|
+
|
|
44
40
|
/**
|
|
45
41
|
* The message describing the cause of the error.
|
|
46
42
|
*
|
|
47
43
|
* @type {string}
|
|
48
44
|
*/
|
|
49
|
-
|
|
50
45
|
this.message = message;
|
|
46
|
+
|
|
51
47
|
/**
|
|
52
48
|
* Native error instance we use to generate the call stack. For some reason
|
|
53
49
|
* some browsers do not generate call stacks for instances of classes
|
|
@@ -55,24 +51,24 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
55
51
|
*
|
|
56
52
|
* @type {Error}
|
|
57
53
|
*/
|
|
58
|
-
|
|
59
54
|
this._nativeError = new Error(message);
|
|
60
|
-
this._nativeError.name = this.name;
|
|
55
|
+
this._nativeError.name = this.name;
|
|
61
56
|
|
|
57
|
+
// improve compatibility with Gecko
|
|
62
58
|
if (this._nativeError.columnNumber) {
|
|
63
59
|
this.lineNumber = this._nativeError.lineNumber;
|
|
64
60
|
this.columnNumber = this._nativeError.columnNumber;
|
|
65
61
|
this.fileName = this._nativeError.fileName;
|
|
66
62
|
}
|
|
63
|
+
|
|
67
64
|
/**
|
|
68
65
|
* The internal cache of the generated stack. The cache is filled upon first
|
|
69
66
|
* access to the {@link ExtensibleError#stack} property.
|
|
70
67
|
*
|
|
71
68
|
* @type {?string}
|
|
72
69
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
70
|
this._stack = null;
|
|
71
|
+
|
|
76
72
|
/**
|
|
77
73
|
* Whether or not the call stack frames referring to the constructors of
|
|
78
74
|
* the custom errors should be excluded from the stack of this error (just
|
|
@@ -81,19 +77,17 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
81
77
|
*
|
|
82
78
|
* @type {boolean}
|
|
83
79
|
*/
|
|
84
|
-
|
|
85
80
|
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
86
81
|
}
|
|
87
|
-
|
|
88
82
|
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
89
83
|
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
84
|
+
|
|
90
85
|
/**
|
|
91
86
|
* The call stack captured at the moment of creation of this error. The
|
|
92
87
|
* formatting of the stack is browser-dependant.
|
|
93
88
|
*
|
|
94
89
|
* @var {string} ExtensibleError#stack
|
|
95
90
|
*/
|
|
96
|
-
|
|
97
91
|
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
98
92
|
configurable: true,
|
|
99
93
|
enumerable: false,
|
|
@@ -101,35 +95,29 @@ Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
|
101
95
|
if (this._stack) {
|
|
102
96
|
return this._stack;
|
|
103
97
|
}
|
|
104
|
-
|
|
105
98
|
let stack = this._nativeError.stack;
|
|
106
|
-
|
|
107
99
|
if (typeof stack !== 'string') {
|
|
108
100
|
return undefined;
|
|
109
|
-
}
|
|
110
|
-
// constructors
|
|
111
|
-
|
|
101
|
+
}
|
|
112
102
|
|
|
103
|
+
// drop the stack trace frames referring to the custom error
|
|
104
|
+
// constructors
|
|
113
105
|
if (this._dropInternalStackFrames) {
|
|
114
106
|
let stackLines = stack.split('\n');
|
|
115
107
|
let inheritanceDepth = 1;
|
|
116
108
|
let currentPrototype = Object.getPrototypeOf(this);
|
|
117
|
-
|
|
118
109
|
while (currentPrototype !== ExtensibleError.prototype) {
|
|
119
110
|
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
120
111
|
inheritanceDepth++;
|
|
121
112
|
}
|
|
122
|
-
|
|
123
113
|
stackLines.splice(1, inheritanceDepth);
|
|
124
114
|
this._stack = stackLines.join('\n');
|
|
125
115
|
} else {
|
|
126
116
|
this._stack = stack;
|
|
127
117
|
}
|
|
128
|
-
|
|
129
118
|
return this._stack;
|
|
130
119
|
}
|
|
131
120
|
});
|
|
132
|
-
|
|
133
121
|
class GenericError extends ExtensibleError {
|
|
134
122
|
constructor(message, params) {
|
|
135
123
|
super(message);
|
|
@@ -141,19 +129,15 @@ class GenericError extends ExtensibleError {
|
|
|
141
129
|
this.status = status;
|
|
142
130
|
this._params = otherParams;
|
|
143
131
|
}
|
|
144
|
-
|
|
145
132
|
get params() {
|
|
146
133
|
return this._params;
|
|
147
134
|
}
|
|
148
|
-
|
|
149
135
|
}
|
|
150
|
-
|
|
151
136
|
const DEV = 'development';
|
|
152
137
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
153
138
|
const ERROR_EVENTS = {
|
|
154
139
|
ERROR: '@merkur/plugin-error.error'
|
|
155
140
|
};
|
|
156
|
-
|
|
157
141
|
function errorPlugin() {
|
|
158
142
|
return {
|
|
159
143
|
async setup(widget) {
|
|
@@ -163,36 +147,31 @@ function errorPlugin() {
|
|
|
163
147
|
};
|
|
164
148
|
return widget;
|
|
165
149
|
},
|
|
166
|
-
|
|
167
150
|
async create(widget) {
|
|
168
151
|
if (ENV === DEV) {
|
|
169
152
|
if (!widget.$in.component) {
|
|
170
153
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-component');
|
|
171
154
|
}
|
|
172
|
-
|
|
173
155
|
if (!widget.$in.eventEmitter) {
|
|
174
156
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-event-emitter');
|
|
175
157
|
}
|
|
176
158
|
}
|
|
177
|
-
|
|
178
159
|
core.hookMethod(widget, 'info', infoHook);
|
|
179
160
|
core.hookMethod(widget, 'load', loadHook);
|
|
180
161
|
core.hookMethod(widget, 'mount', mountHook);
|
|
181
162
|
core.hookMethod(widget, 'update', updateHook);
|
|
182
163
|
return widget;
|
|
183
164
|
}
|
|
184
|
-
|
|
185
165
|
};
|
|
186
|
-
}
|
|
166
|
+
}
|
|
187
167
|
|
|
168
|
+
// LIFECYCLE HOOKS
|
|
188
169
|
|
|
189
170
|
async function loadHook(widget, originalLoad, ...rest) {
|
|
190
171
|
let result = {};
|
|
191
|
-
|
|
192
172
|
if (widget.error.status) {
|
|
193
173
|
return result;
|
|
194
174
|
}
|
|
195
|
-
|
|
196
175
|
try {
|
|
197
176
|
result = await originalLoad(...rest);
|
|
198
177
|
} catch (error) {
|
|
@@ -200,10 +179,8 @@ async function loadHook(widget, originalLoad, ...rest) {
|
|
|
200
179
|
setErrorInfo(widget, error);
|
|
201
180
|
emitError(widget, error);
|
|
202
181
|
}
|
|
203
|
-
|
|
204
182
|
return result;
|
|
205
183
|
}
|
|
206
|
-
|
|
207
184
|
async function infoHook(widget, originalInfo, ...rest) {
|
|
208
185
|
const result = await originalInfo(...rest);
|
|
209
186
|
return {
|
|
@@ -211,34 +188,29 @@ async function infoHook(widget, originalInfo, ...rest) {
|
|
|
211
188
|
...result
|
|
212
189
|
};
|
|
213
190
|
}
|
|
214
|
-
|
|
215
191
|
async function mountHook(widget, originalMount, ...rest) {
|
|
216
192
|
return renderContent(widget, originalMount, rest);
|
|
217
193
|
}
|
|
218
|
-
|
|
219
194
|
async function updateHook(widget, originalUpdate, ...rest) {
|
|
220
195
|
return renderContent(widget, originalUpdate, rest);
|
|
221
|
-
}
|
|
196
|
+
}
|
|
222
197
|
|
|
198
|
+
// HELPER FUNCTIONS
|
|
223
199
|
|
|
224
200
|
function setErrorInfo(widget, error) {
|
|
225
201
|
widget.error.status = error.status;
|
|
226
202
|
widget.error.message = error.message;
|
|
227
|
-
|
|
228
203
|
if (ENV === DEV) {
|
|
229
204
|
widget.error.stack = error.stack;
|
|
230
205
|
}
|
|
231
206
|
}
|
|
232
|
-
|
|
233
207
|
function emitError(widget, error) {
|
|
234
208
|
widget.emit(ERROR_EVENTS.ERROR, {
|
|
235
209
|
error
|
|
236
210
|
});
|
|
237
211
|
}
|
|
238
|
-
|
|
239
212
|
async function renderContent(widget, method, properties) {
|
|
240
213
|
let result = null;
|
|
241
|
-
|
|
242
214
|
if (widget.error.status) {
|
|
243
215
|
// error was captured in an earlier lifecycle method
|
|
244
216
|
try {
|
|
@@ -252,7 +224,6 @@ async function renderContent(widget, method, properties) {
|
|
|
252
224
|
return result;
|
|
253
225
|
}
|
|
254
226
|
}
|
|
255
|
-
|
|
256
227
|
try {
|
|
257
228
|
// no earlier error captured
|
|
258
229
|
result = await method(...properties);
|
|
@@ -261,12 +232,12 @@ async function renderContent(widget, method, properties) {
|
|
|
261
232
|
// save error info
|
|
262
233
|
err.status = err.status || 500;
|
|
263
234
|
setErrorInfo(widget, err);
|
|
264
|
-
emitError(widget, err);
|
|
235
|
+
emitError(widget, err);
|
|
265
236
|
|
|
237
|
+
// try rendering again
|
|
266
238
|
return renderContent(widget, method, properties);
|
|
267
239
|
}
|
|
268
240
|
}
|
|
269
|
-
|
|
270
241
|
exports.ERROR_EVENTS = ERROR_EVENTS;
|
|
271
242
|
exports.GenericError = GenericError;
|
|
272
243
|
exports.errorPlugin = errorPlugin;
|
package/lib/index.es9.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hookMethod } from '@merkur/core';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Base class of custom error classes, extending the native `Error` class.
|
|
4
5
|
*
|
|
@@ -15,16 +16,13 @@ import { hookMethod } from '@merkur/core';
|
|
|
15
16
|
* call stack frames are dropped by the JS engine).
|
|
16
17
|
* This flag is enabled by default.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
20
20
|
if (!(this instanceof ExtensibleError)) {
|
|
21
21
|
throw new TypeError('Cannot call a class as a function');
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
if (this.constructor === ExtensibleError) {
|
|
25
24
|
throw new TypeError('The ExtensibleError is an abstract class and ' + 'must be extended before it can be instantiated.');
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
Error.call(this, message); // super-constructor call;
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -32,15 +30,15 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
32
30
|
*
|
|
33
31
|
* @type {string}
|
|
34
32
|
*/
|
|
35
|
-
|
|
36
33
|
this.name = this.constructor.name;
|
|
34
|
+
|
|
37
35
|
/**
|
|
38
36
|
* The message describing the cause of the error.
|
|
39
37
|
*
|
|
40
38
|
* @type {string}
|
|
41
39
|
*/
|
|
42
|
-
|
|
43
40
|
this.message = message;
|
|
41
|
+
|
|
44
42
|
/**
|
|
45
43
|
* Native error instance we use to generate the call stack. For some reason
|
|
46
44
|
* some browsers do not generate call stacks for instances of classes
|
|
@@ -48,24 +46,24 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
48
46
|
*
|
|
49
47
|
* @type {Error}
|
|
50
48
|
*/
|
|
51
|
-
|
|
52
49
|
this._nativeError = new Error(message);
|
|
53
|
-
this._nativeError.name = this.name;
|
|
50
|
+
this._nativeError.name = this.name;
|
|
54
51
|
|
|
52
|
+
// improve compatibility with Gecko
|
|
55
53
|
if (this._nativeError.columnNumber) {
|
|
56
54
|
this.lineNumber = this._nativeError.lineNumber;
|
|
57
55
|
this.columnNumber = this._nativeError.columnNumber;
|
|
58
56
|
this.fileName = this._nativeError.fileName;
|
|
59
57
|
}
|
|
58
|
+
|
|
60
59
|
/**
|
|
61
60
|
* The internal cache of the generated stack. The cache is filled upon first
|
|
62
61
|
* access to the {@link ExtensibleError#stack} property.
|
|
63
62
|
*
|
|
64
63
|
* @type {?string}
|
|
65
64
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
65
|
this._stack = null;
|
|
66
|
+
|
|
69
67
|
/**
|
|
70
68
|
* Whether or not the call stack frames referring to the constructors of
|
|
71
69
|
* the custom errors should be excluded from the stack of this error (just
|
|
@@ -74,19 +72,17 @@ function ExtensibleError(message, dropInternalStackFrames = true) {
|
|
|
74
72
|
*
|
|
75
73
|
* @type {boolean}
|
|
76
74
|
*/
|
|
77
|
-
|
|
78
75
|
this._dropInternalStackFrames = dropInternalStackFrames;
|
|
79
76
|
}
|
|
80
|
-
|
|
81
77
|
ExtensibleError.prototype = Object.create(Error.prototype);
|
|
82
78
|
ExtensibleError.prototype.constructor = ExtensibleError;
|
|
79
|
+
|
|
83
80
|
/**
|
|
84
81
|
* The call stack captured at the moment of creation of this error. The
|
|
85
82
|
* formatting of the stack is browser-dependant.
|
|
86
83
|
*
|
|
87
84
|
* @var {string} ExtensibleError#stack
|
|
88
85
|
*/
|
|
89
|
-
|
|
90
86
|
Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
91
87
|
configurable: true,
|
|
92
88
|
enumerable: false,
|
|
@@ -94,35 +90,29 @@ Object.defineProperty(ExtensibleError.prototype, 'stack', {
|
|
|
94
90
|
if (this._stack) {
|
|
95
91
|
return this._stack;
|
|
96
92
|
}
|
|
97
|
-
|
|
98
93
|
let stack = this._nativeError.stack;
|
|
99
|
-
|
|
100
94
|
if (typeof stack !== 'string') {
|
|
101
95
|
return undefined;
|
|
102
|
-
}
|
|
103
|
-
// constructors
|
|
104
|
-
|
|
96
|
+
}
|
|
105
97
|
|
|
98
|
+
// drop the stack trace frames referring to the custom error
|
|
99
|
+
// constructors
|
|
106
100
|
if (this._dropInternalStackFrames) {
|
|
107
101
|
let stackLines = stack.split('\n');
|
|
108
102
|
let inheritanceDepth = 1;
|
|
109
103
|
let currentPrototype = Object.getPrototypeOf(this);
|
|
110
|
-
|
|
111
104
|
while (currentPrototype !== ExtensibleError.prototype) {
|
|
112
105
|
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
113
106
|
inheritanceDepth++;
|
|
114
107
|
}
|
|
115
|
-
|
|
116
108
|
stackLines.splice(1, inheritanceDepth);
|
|
117
109
|
this._stack = stackLines.join('\n');
|
|
118
110
|
} else {
|
|
119
111
|
this._stack = stack;
|
|
120
112
|
}
|
|
121
|
-
|
|
122
113
|
return this._stack;
|
|
123
114
|
}
|
|
124
115
|
});
|
|
125
|
-
|
|
126
116
|
class GenericError extends ExtensibleError {
|
|
127
117
|
constructor(message, params) {
|
|
128
118
|
super(message);
|
|
@@ -134,19 +124,15 @@ class GenericError extends ExtensibleError {
|
|
|
134
124
|
this.status = status;
|
|
135
125
|
this._params = otherParams;
|
|
136
126
|
}
|
|
137
|
-
|
|
138
127
|
get params() {
|
|
139
128
|
return this._params;
|
|
140
129
|
}
|
|
141
|
-
|
|
142
130
|
}
|
|
143
|
-
|
|
144
131
|
const DEV = 'development';
|
|
145
132
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
146
133
|
const ERROR_EVENTS = {
|
|
147
134
|
ERROR: '@merkur/plugin-error.error'
|
|
148
135
|
};
|
|
149
|
-
|
|
150
136
|
function errorPlugin() {
|
|
151
137
|
return {
|
|
152
138
|
async setup(widget) {
|
|
@@ -156,36 +142,31 @@ function errorPlugin() {
|
|
|
156
142
|
};
|
|
157
143
|
return widget;
|
|
158
144
|
},
|
|
159
|
-
|
|
160
145
|
async create(widget) {
|
|
161
146
|
if (ENV === DEV) {
|
|
162
147
|
if (!widget.$in.component) {
|
|
163
148
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-component');
|
|
164
149
|
}
|
|
165
|
-
|
|
166
150
|
if (!widget.$in.eventEmitter) {
|
|
167
151
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-event-emitter');
|
|
168
152
|
}
|
|
169
153
|
}
|
|
170
|
-
|
|
171
154
|
hookMethod(widget, 'info', infoHook);
|
|
172
155
|
hookMethod(widget, 'load', loadHook);
|
|
173
156
|
hookMethod(widget, 'mount', mountHook);
|
|
174
157
|
hookMethod(widget, 'update', updateHook);
|
|
175
158
|
return widget;
|
|
176
159
|
}
|
|
177
|
-
|
|
178
160
|
};
|
|
179
|
-
}
|
|
161
|
+
}
|
|
180
162
|
|
|
163
|
+
// LIFECYCLE HOOKS
|
|
181
164
|
|
|
182
165
|
async function loadHook(widget, originalLoad, ...rest) {
|
|
183
166
|
let result = {};
|
|
184
|
-
|
|
185
167
|
if (widget.error.status) {
|
|
186
168
|
return result;
|
|
187
169
|
}
|
|
188
|
-
|
|
189
170
|
try {
|
|
190
171
|
result = await originalLoad(...rest);
|
|
191
172
|
} catch (error) {
|
|
@@ -193,10 +174,8 @@ async function loadHook(widget, originalLoad, ...rest) {
|
|
|
193
174
|
setErrorInfo(widget, error);
|
|
194
175
|
emitError(widget, error);
|
|
195
176
|
}
|
|
196
|
-
|
|
197
177
|
return result;
|
|
198
178
|
}
|
|
199
|
-
|
|
200
179
|
async function infoHook(widget, originalInfo, ...rest) {
|
|
201
180
|
const result = await originalInfo(...rest);
|
|
202
181
|
return {
|
|
@@ -204,34 +183,29 @@ async function infoHook(widget, originalInfo, ...rest) {
|
|
|
204
183
|
...result
|
|
205
184
|
};
|
|
206
185
|
}
|
|
207
|
-
|
|
208
186
|
async function mountHook(widget, originalMount, ...rest) {
|
|
209
187
|
return renderContent(widget, originalMount, rest);
|
|
210
188
|
}
|
|
211
|
-
|
|
212
189
|
async function updateHook(widget, originalUpdate, ...rest) {
|
|
213
190
|
return renderContent(widget, originalUpdate, rest);
|
|
214
|
-
}
|
|
191
|
+
}
|
|
215
192
|
|
|
193
|
+
// HELPER FUNCTIONS
|
|
216
194
|
|
|
217
195
|
function setErrorInfo(widget, error) {
|
|
218
196
|
widget.error.status = error.status;
|
|
219
197
|
widget.error.message = error.message;
|
|
220
|
-
|
|
221
198
|
if (ENV === DEV) {
|
|
222
199
|
widget.error.stack = error.stack;
|
|
223
200
|
}
|
|
224
201
|
}
|
|
225
|
-
|
|
226
202
|
function emitError(widget, error) {
|
|
227
203
|
widget.emit(ERROR_EVENTS.ERROR, {
|
|
228
204
|
error
|
|
229
205
|
});
|
|
230
206
|
}
|
|
231
|
-
|
|
232
207
|
async function renderContent(widget, method, properties) {
|
|
233
208
|
let result = null;
|
|
234
|
-
|
|
235
209
|
if (widget.error.status) {
|
|
236
210
|
// error was captured in an earlier lifecycle method
|
|
237
211
|
try {
|
|
@@ -245,7 +219,6 @@ async function renderContent(widget, method, properties) {
|
|
|
245
219
|
return result;
|
|
246
220
|
}
|
|
247
221
|
}
|
|
248
|
-
|
|
249
222
|
try {
|
|
250
223
|
// no earlier error captured
|
|
251
224
|
result = await method(...properties);
|
|
@@ -254,10 +227,10 @@ async function renderContent(widget, method, properties) {
|
|
|
254
227
|
// save error info
|
|
255
228
|
err.status = err.status || 500;
|
|
256
229
|
setErrorInfo(widget, err);
|
|
257
|
-
emitError(widget, err);
|
|
230
|
+
emitError(widget, err);
|
|
258
231
|
|
|
232
|
+
// try rendering again
|
|
259
233
|
return renderContent(widget, method, properties);
|
|
260
234
|
}
|
|
261
235
|
}
|
|
262
|
-
|
|
263
236
|
export { ERROR_EVENTS, GenericError, errorPlugin, renderContent, setErrorInfo };
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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",
|
|
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",_),(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?Object.setPrototypeOf.bind():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.bind():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 P.apply(this,arguments)}function P(){return P=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)})),P.apply(this,arguments)}function _(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.31.0",
|
|
4
4
|
"description": "Merkur plugin for error handling.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -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.
|
|
53
|
+
"@merkur/core": "^0.31.0",
|
|
54
|
+
"@merkur/plugin-component": "^0.31.0",
|
|
55
55
|
"rollup": "^2.70.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@merkur/core": "*",
|
|
59
59
|
"@merkur/plugin-component": "*"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "ef1b38f23e43e2fd7ef6a2bec680fb40a2de3715"
|
|
62
62
|
}
|