UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 2.57 kB
{"version":3,"file":"errors.cjs","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Stringify an unknown error value for CLI output. A plain-object rejection\n * coerces to \"[object Object]\" in a template literal; a structured payload\n * (Zod results, `{ message, stack }` shapes, result `error` fields) must\n * render its actual content or the real failure is swallowed.\n */\nexport function formatUnknownError(error: unknown): string {\n if (error === null || error === undefined || error === \"\") return \"Unknown error\";\n if (typeof error === \"string\") return error;\n if (typeof error === \"number\" || typeof error === \"boolean\" || typeof error === \"bigint\") {\n return String(error);\n }\n if (typeof error === \"symbol\") return error.description ?? \"Symbol\";\n if (error instanceof Error) {\n const parts = [error.message || error.name];\n if (error.cause !== undefined && error.cause !== null) {\n parts.push(`(cause: ${formatUnknownError(error.cause)})`);\n }\n return parts.join(\" \");\n }\n if (typeof error === \"object\") {\n const record = error as Record<string, unknown>;\n const message =\n typeof record.message === \"string\" && record.message.trim() !== \"\"\n ? record.message\n : typeof record.error === \"string\" && record.error.trim() !== \"\"\n ? record.error\n : null;\n if (message) return message;\n try {\n const serialized = JSON.stringify(error, null, 2);\n if (serialized && serialized !== \"{}\" && serialized !== \"[]\") return serialized;\n } catch {\n // circular or non-serializable — fall through to the tagged form\n }\n return Object.prototype.toString.call(error);\n }\n return String(error);\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,mBAAmB,OAAwB;CACzD,IAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,IAAI,OAAO;CAClE,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU,UAC9E,OAAO,OAAO,KAAK;CAErB,IAAI,OAAO,UAAU,UAAU,OAAO,MAAM,eAAe;CAC3D,IAAI,iBAAiB,OAAO;EAC1B,MAAM,QAAQ,CAAC,MAAM,WAAW,MAAM,IAAI;EAC1C,IAAI,MAAM,UAAU,UAAa,MAAM,UAAU,MAC/C,MAAM,KAAK,WAAW,mBAAmB,MAAM,KAAK,EAAE,EAAE;EAE1D,OAAO,MAAM,KAAK,GAAG;CACvB;CACA,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,SAAS;EACf,MAAM,UACJ,OAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,KAAK,MAAM,KAC5D,OAAO,UACP,OAAO,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,MAAM,KAC1D,OAAO,QACP;EACR,IAAI,SAAS,OAAO;EACpB,IAAI;GACF,MAAM,aAAa,KAAK,UAAU,OAAO,MAAM,CAAC;GAChD,IAAI,cAAc,eAAe,QAAQ,eAAe,MAAM,OAAO;EACvE,QAAQ,CAER;EACA,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK;CAC7C;CACA,OAAO,OAAO,KAAK;AACrB"}