UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 772 B
import{isObject}from"#shared/guards.js";function toErrorMessage(e){return e instanceof Error?e.message:typeof e==`string`?e:e==null?String(e):isObject(e)?typeof e.message==`string`&&e.message.length>0?e.message:safeJsonStringify(e):String(e)}function toError(e){if(e instanceof Error)return e;let t=Error(toErrorMessage(e));return isObject(e)?(typeof e.name==`string`&&e.name.length>0&&(t.name=e.name),typeof e.stack==`string`&&e.stack.length>0&&(t.stack=e.stack),`cause`in e&&e.cause!==void 0&&e.cause!==e&&(t.cause=e.cause),t):t}function*walkCauseChain(e){let t=new Set,n=e;for(;isObject(n)&&!t.has(n);)t.add(n),yield n,n=n.cause}function safeJsonStringify(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}export{toError,toErrorMessage,walkCauseChain};