/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/yerror@11.0.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{EOL}from"node:os";class YError extends Error{code;debug;cause;constructor(r="E_UNEXPECTED",t,o={}){super(r),this.code=r,this.debug=t||[],this.cause=o.cause,this.name=this.toString(),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}static wrap(r,t,o){const e=looksLikeAYErrorCode(r.message);return t||(t=e?r.message:"E_UNEXPECTED"),new YError(t,o,{cause:r})}static cast(r,t,o){return looksLikeAYError(r)?r:YError.wrap(r,t,o)}static bump(r,t,o){return looksLikeAYError(r)?YError.wrap(r,r.code,r.debug):YError.wrap(r,t,o)}toString(){let r;try{r=JSON.stringify(this.debug)}catch{r="<circular>"}return`${this.constructor.name}: ${this.code} (${r})`}}export function printStackTrace(r){let t;if("object"==typeof r&&r instanceof Error&&"string"==typeof r.stack)t=r.stack;else try{t=`[no_stack_trace]: error is serializable (${JSON.stringify(r)})`}catch{t=`[no_stack_trace]: error is circular ("${null!=r&&"function"==typeof r.toString?r.toString():typeof r}")`}return`${t}${r instanceof Error&&r.cause?EOL+"Caused by: "+printStackTrace(r.cause):""}`}export function looksLikeAYErrorCode(r){return/^([A-Z0-9_]+)$/.test(r)}export function looksLikeAYError(r){return!!(r instanceof YError)||!!(r&&"object"==typeof r&&r.constructor&&r.constructor.name&&r.constructor.name.endsWith("Error")&&"code"in r&&"string"==typeof r.code&&looksLikeAYErrorCode(r.code)&&"debug"in r&&r.debug&&r.debug instanceof Array)}export function hasYErrorCode(r,t){return looksLikeAYError(r)&&r.code===t}export function pickYErrorWithCode(r,t){do{if(hasYErrorCode(r,t))return r;r=r&&"object"==typeof r&&"cause"in r&&r.cause}while(r);return null}export{YError};
//# sourceMappingURL=/sm/84357a9701f828a038392e5ab9ed8bdb072cef5b7385f4988d064827c021d5d3.map