- "\nexport const prettifyStandardSchemaError = (error: unknown): string | null => {\n if (!looksLikeStandardSchemaFailure(error)) return null\n\n const issues = [...error.issues]\n .map(issue => {\n const path = issue.path || []\n const primitivePathSegments = path.map(segment => {\n if (typeof segment === 'string' || typeof segment === 'number' || typeof segment === 'symbol') return segment\n return segment.key\n })\n const dotPath = toDotPath(primitivePathSegments)\n return {\n issue,\n path,\n primitivePathSegments,\n dotPath,\n }\n })\n .sort((a, b) => a.path.length - b.path.length)\n\n const lines: string[] = []\n\n for (const {issue, dotPath} of issues) {\n let message = `✖ ${issue.message}`\n if (dotPath) message += ` → at ${dotPath}`\n lines.push(message)\n }\n\n return lines.join('\\n')\n}\n\nexport function toDotPath(path: (string | number | symbol)[]): string {\n const segs: string[] = []\n for (const seg of path) {\n if (typeof seg === 'number') segs.push(`[${seg}]`)\n else if (typeof seg === 'symbol') segs.push(`[${JSON.stringify(String(seg))}]`)\n else if (/[^\\w$]/.test(seg)) segs.push(`[${JSON.stringify(seg)}]`)\n else {\n if (segs.length) segs.push('.')\n segs.push(seg)\n }\n }\n\n return segs.join('')\n}\n\nexport class StandardSchemaV1Error extends Error implements StandardSchemaV1.FailureResult {\n issues: StandardSchemaV1.FailureResult['issues']\n constructor(failure: StandardSchemaV1.FailureResult, options?: {cause?: Error}) {\n super('Standard Schema error - details in `issues`.', options)\n this.issues = failure.issues\n }\n}\n"
0 commit comments