Skip to content

Commit

Permalink
fix: Standardize error reporting code (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: huang yao <[email protected]>
  • Loading branch information
kirakiray and kirakiray authored Jan 22, 2024
1 parent 94d8206 commit 945be76
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 17 deletions.
7 changes: 4 additions & 3 deletions dist/drill.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! drill.js - v5.3.5 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
//! drill.js - v5.3.6 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -188,8 +188,9 @@
});

const wrapError = (desc, error) => {
const err = new Error(`${desc} \n ${error.toString()}`);
err.error = error;
const err = new Error(`${desc} \n ${error.toString()}`, {
cause: error,
});
return err;
};

Expand Down
4 changes: 2 additions & 2 deletions dist/drill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/drill.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/drill.min.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//! drill.js - v5.3.5 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
class t{constructor(){this._middlewares=new Map}use(t){const e=Math.random().toString(32).slice(2);return this._middlewares.set(e,t),e}unuse(t){return this._middlewares.delete(t)}async run(t){let e=-1;const s=Array.from(this._middlewares.values()),n=async()=>{e++,e<s.length&&await s[e](t,n)};await n()}}const e=new Map,s=async(t,s)=>{const n=new URL(t),a=s.includes("-direct")?t:`${n.origin}${n.pathname}`;let r=e.get(a);r||(r=fetch(a),e.set(a,r));return(await r).clone()},n={},a=(e,s)=>{(n[e]||(n[e]=new t)).use(s)},r=(t,e)=>{t instanceof Function&&(e=t,t=["js","mjs"]),t instanceof Array?t.forEach((t=>{a(t,e)})):a(t,e)};r(["mjs","js"],(async(t,e)=>{if(!t.result){const{url:e,params:s}=t,n=new URL(e),a=/^blob:/.test(e)||/^data:/.test(e);try{a||s.includes("-direct")?t.result=await import(e):t.result=await import(`${n.origin}${n.pathname}`)}catch(s){const n=i(`Failed to load module ${t.realUrl||e}`,s);throw a&&console.log("Failed to load module:",t),n}}await e()})),r(["txt","html","htm"],(async(t,e)=>{if(!t.result){const{url:e,params:n}=t;let a;try{a=await s(e,n)}catch(t){throw i(`Load ${e} failed`,t)}if(!/^2.{2}$/.test(a.status))throw new Error(`Load ${e} failed: status code ${a.status}`);t.result=await a.text()}await e()})),r("json",(async(t,e)=>{if(!t.result){const{url:e,params:n}=t;t.result=await s(e,n).then((t=>t.json()))}await e()})),r("wasm",(async(t,e)=>{if(!t.result){const{url:e,params:n}=t,a=await s(e,n).then((t=>t.arrayBuffer())),r=await WebAssembly.compile(a),i=new WebAssembly.Instance(r);t.result=i.exports}await e()})),r("css",(async(t,e)=>{if(!t.result){const{url:e,element:n,params:a}=t;if(n){const t=document.createElement("link");t.rel="stylesheet",t.href=e;const s=n.getRootNode();let a;s===document?s.head.append(t):s.appendChild(t),n.addEventListener("disconnected",a=e=>{t.remove(),n.removeEventListener("disconnected",a)})}else t.result=await s(e,a).then((t=>t.text()))}await e()}));const i=(t,e)=>{const s=new Error(`${t} \n ${e.toString()}`);return s.error=e,s},o={};const l=(t,e)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;const[s,...n]=t.split(" ");let a=s;if(/^@/.test(s)){const[t,...e]=s.split("/");if(!o[t])throw`No alias defined ${t}`;a=[o[t].replace(/\/$/,""),...e].join("/")}if("undefined"!=typeof location){const t=e?new URL(e,location.href):location.href;a=new URL(a,t).href}return n.length?`${a} ${n.join(" ")}`:a},c=Symbol("loaded"),d=async(t,e)=>{const s=new URL(t),{pathname:a}=s;let r,i=null;e.params&&e.params.forEach((t=>{/^\..+/.test(t)?r=t.replace(/^\.(.+)/,"$1"):/^\-\-real/.test(t)&&(i=t.replace(/^\-\-real\:/,""))})),r||(r=a.slice(2+(a.lastIndexOf(".")-1>>>0)));const o={url:t,result:null,realUrl:i,...e},l=n[r];if(l?await l.run(o):o.result=fetch(t),e&&e.element){const{element:t}=e;t[c]=!0;const s=new Event("load");t.dispatchEvent(s)}return e.params&&e.params.includes("-ctx")?o:o.result};function u(t,e){return((t,e)=>(t||(t={url:document.location.href}),s=>{let[n,...a]=s.split(" ");const r=l(n,t.url);return d(r,{params:a,...e})}))(t,e)}Object.assign(u,{use:r});class h extends HTMLElement{constructor(...t){super(...t),this[c]=!1,Object.defineProperties(this,{loaded:{get:()=>this[c]}}),this._init()}_init(){if(this.__initSrc||this.attributes.hasOwnProperty("pause"))return;let t=this.getAttribute("src");if(!t)return;this.__initSrc=t;lm(void 0,{element:this})(t),Object.defineProperties(this,{src:{configurable:!0,value:t}})}connectedCallback(){const t=new CustomEvent("connected");t.root=this._root=this.getRootNode(),this.dispatchEvent(t)}disconnectedCallback(){const t=new CustomEvent("disconnected");t.root=this._root,delete this._root,this.dispatchEvent(t)}attributeChangedCallback(t,e,s){"src"===t?s&&null===e?this._init():this.__initSrc&&e&&s!==this.__initSrc&&(console.warn(`${this.tagName.toLowerCase()} change src is invalid, only the first change will be loaded`),this.setAttribute("src",this.__initSrc)):"pause"===t&&null===s&&this._init()}static get observedAttributes(){return["src","pause"]}}class m extends h{constructor(...t){super(...t)}}const w=()=>{customElements.define("load-module",h),customElements.define("l-m",m),window.removeEventListener("load",w)};"complete"===document.readyState?w():window.addEventListener("load",w),u.config=async function(t){const{alias:e}=t;return e&&Object.entries(e).forEach((([t,e])=>{if(/^@.+/.test(t)){if(o[t])throw`Alias already exists: '${t}'`;if(/^\./.test(e))throw`The address does not match the specification, please use '/' or or the beginning of the protocol: '${e}'`;o[t]=e}})),!0},u.path=l,Object.freeze(u),window.lm=u;export{u as default};
//! drill.js - v5.3.6 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
class t{constructor(){this._middlewares=new Map}use(t){const e=Math.random().toString(32).slice(2);return this._middlewares.set(e,t),e}unuse(t){return this._middlewares.delete(t)}async run(t){let e=-1;const s=Array.from(this._middlewares.values()),n=async()=>{e++,e<s.length&&await s[e](t,n)};await n()}}const e=new Map,s=async(t,s)=>{const n=new URL(t),a=s.includes("-direct")?t:`${n.origin}${n.pathname}`;let r=e.get(a);r||(r=fetch(a),e.set(a,r));return(await r).clone()},n={},a=(e,s)=>{(n[e]||(n[e]=new t)).use(s)},r=(t,e)=>{t instanceof Function&&(e=t,t=["js","mjs"]),t instanceof Array?t.forEach((t=>{a(t,e)})):a(t,e)};r(["mjs","js"],(async(t,e)=>{if(!t.result){const{url:e,params:s}=t,n=new URL(e),a=/^blob:/.test(e)||/^data:/.test(e);try{a||s.includes("-direct")?t.result=await import(e):t.result=await import(`${n.origin}${n.pathname}`)}catch(s){const n=i(`Failed to load module ${t.realUrl||e}`,s);throw a&&console.log("Failed to load module:",t),n}}await e()})),r(["txt","html","htm"],(async(t,e)=>{if(!t.result){const{url:e,params:n}=t;let a;try{a=await s(e,n)}catch(t){throw i(`Load ${e} failed`,t)}if(!/^2.{2}$/.test(a.status))throw new Error(`Load ${e} failed: status code ${a.status}`);t.result=await a.text()}await e()})),r("json",(async(t,e)=>{if(!t.result){const{url:e,params:n}=t;t.result=await s(e,n).then((t=>t.json()))}await e()})),r("wasm",(async(t,e)=>{if(!t.result){const{url:e,params:n}=t,a=await s(e,n).then((t=>t.arrayBuffer())),r=await WebAssembly.compile(a),i=new WebAssembly.Instance(r);t.result=i.exports}await e()})),r("css",(async(t,e)=>{if(!t.result){const{url:e,element:n,params:a}=t;if(n){const t=document.createElement("link");t.rel="stylesheet",t.href=e;const s=n.getRootNode();let a;s===document?s.head.append(t):s.appendChild(t),n.addEventListener("disconnected",a=e=>{t.remove(),n.removeEventListener("disconnected",a)})}else t.result=await s(e,a).then((t=>t.text()))}await e()}));const i=(t,e)=>new Error(`${t} \n ${e.toString()}`,{cause:e}),o={};const l=(t,e)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;const[s,...n]=t.split(" ");let a=s;if(/^@/.test(s)){const[t,...e]=s.split("/");if(!o[t])throw`No alias defined ${t}`;a=[o[t].replace(/\/$/,""),...e].join("/")}if("undefined"!=typeof location){const t=e?new URL(e,location.href):location.href;a=new URL(a,t).href}return n.length?`${a} ${n.join(" ")}`:a},c=Symbol("loaded"),d=async(t,e)=>{const s=new URL(t),{pathname:a}=s;let r,i=null;e.params&&e.params.forEach((t=>{/^\..+/.test(t)?r=t.replace(/^\.(.+)/,"$1"):/^\-\-real/.test(t)&&(i=t.replace(/^\-\-real\:/,""))})),r||(r=a.slice(2+(a.lastIndexOf(".")-1>>>0)));const o={url:t,result:null,realUrl:i,...e},l=n[r];if(l?await l.run(o):o.result=fetch(t),e&&e.element){const{element:t}=e;t[c]=!0;const s=new Event("load");t.dispatchEvent(s)}return e.params&&e.params.includes("-ctx")?o:o.result};function u(t,e){return((t,e)=>(t||(t={url:document.location.href}),s=>{let[n,...a]=s.split(" ");const r=l(n,t.url);return d(r,{params:a,...e})}))(t,e)}Object.assign(u,{use:r});class h extends HTMLElement{constructor(...t){super(...t),this[c]=!1,Object.defineProperties(this,{loaded:{get:()=>this[c]}}),this._init()}_init(){if(this.__initSrc||this.attributes.hasOwnProperty("pause"))return;let t=this.getAttribute("src");if(!t)return;this.__initSrc=t;lm(void 0,{element:this})(t),Object.defineProperties(this,{src:{configurable:!0,value:t}})}connectedCallback(){const t=new CustomEvent("connected");t.root=this._root=this.getRootNode(),this.dispatchEvent(t)}disconnectedCallback(){const t=new CustomEvent("disconnected");t.root=this._root,delete this._root,this.dispatchEvent(t)}attributeChangedCallback(t,e,s){"src"===t?s&&null===e?this._init():this.__initSrc&&e&&s!==this.__initSrc&&(console.warn(`${this.tagName.toLowerCase()} change src is invalid, only the first change will be loaded`),this.setAttribute("src",this.__initSrc)):"pause"===t&&null===s&&this._init()}static get observedAttributes(){return["src","pause"]}}class m extends h{constructor(...t){super(...t)}}const w=()=>{customElements.define("load-module",h),customElements.define("l-m",m),window.removeEventListener("load",w)};"complete"===document.readyState?w():window.addEventListener("load",w),u.config=async function(t){const{alias:e}=t;return e&&Object.entries(e).forEach((([t,e])=>{if(/^@.+/.test(t)){if(o[t])throw`Alias already exists: '${t}'`;if(/^\./.test(e))throw`The address does not match the specification, please use '/' or or the beginning of the protocol: '${e}'`;o[t]=e}})),!0},u.path=l,Object.freeze(u),window.lm=u;export{u as default};
//# sourceMappingURL=drill.min.mjs.map
2 changes: 1 addition & 1 deletion dist/drill.min.mjs.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/drill.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! drill.js - v5.3.5 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
//! drill.js - v5.3.6 https://github.com/kirakiray/drill.js (c) 2018-2024 YAO
const getOid = () => Math.random().toString(32).slice(2);

class Onion {
Expand Down Expand Up @@ -182,8 +182,9 @@ use("css", async (ctx, next) => {
});

const wrapError = (desc, error) => {
const err = new Error(`${desc} \n ${error.toString()}`);
err.error = error;
const err = new Error(`${desc} \n ${error.toString()}`, {
cause: error,
});
return err;
};

Expand Down
Loading

0 comments on commit 945be76

Please sign in to comment.