every-plugin 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors.cjs +105 -79
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +164 -5
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +164 -5
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +97 -81
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/dist/package.mjs.map +1 -1
- package/dist/plugin.cjs +3 -0
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +4 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/errors.cjs +19 -0
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.d.cts +11 -5
- package/dist/runtime/errors.d.cts.map +1 -1
- package/dist/runtime/errors.d.mts +11 -5
- package/dist/runtime/errors.d.mts.map +1 -1
- package/dist/runtime/errors.mjs +20 -2
- package/dist/runtime/errors.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":["Data","lines: string[]","ORPCError"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;;AAIA,IAAa,qBAAb,cAAwCA,YAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2CA,YAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqCA,YAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAAI,MAAM,QAAS,QAAO,MAAM;AAChC,MAAK,MAAc,iBAAiB,MACnC,QAAO,oBAAqB,MAAc,MAAM;;AAIlD,KAAI,iBAAiB,kBAAkB,MAAM,QAAQ,OACpD,QAAO,MAAM,OAAO,KAAI,MAAK,oBAAoB,EAAE,CAAC,CAAC,KAAK,KAAK;AAGhE,KAAI,OAAO,UAAU,YAAY,aAAa,MAC7C,QAAO,OAAQ,MAAc,QAAQ;AAGtC,QAAO,OAAO,MAAM;;AAGrB,MAAM,yBAAyB,OAAY,OAAe,eAA+B;AACxF,KAAI,SAAS,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sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n\tif (!error || typeof error !== 'object') return error;\n\t\n\tif ('cause' in error) {\n\t\tconst cause = (error as { cause?: unknown }).cause;\n\t\t\n\t\tif (cause && typeof cause === 'object' && '_tag' in cause) {\n\t\t\ttry {\n\t\t\t\tconst squashed = Cause.squash(cause as Cause.Cause<unknown>);\n\t\t\t\tif (squashed instanceof ORPCError) {\n\t\t\t\t\treturn squashed;\n\t\t\t\t}\n\t\t\t\treturn squashed;\n\t\t\t} catch {\n\t\t\t\t// Not a valid Cause\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (cause instanceof ORPCError) {\n\t\t\treturn cause;\n\t\t}\n\t}\n\t\n\treturn error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;;AAIA,IAAa,qBAAb,cAAwCA,YAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2CA,YAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqCA,YAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAAI,MAAM,QAAS,QAAO,MAAM;AAChC,MAAK,MAAc,iBAAiB,MACnC,QAAO,oBAAqB,MAAc,MAAM;;AAIlD,KAAI,iBAAiB,kBAAkB,MAAM,QAAQ,OACpD,QAAO,MAAM,OAAO,KAAI,MAAK,oBAAoB,EAAE,CAAC,CAAC,KAAK,KAAK;AAGhE,KAAI,OAAO,UAAU,YAAY,aAAa,MAC7C,QAAO,OAAQ,MAAc,QAAQ;AAGtC,QAAO,OAAO,MAAM;;AAGrB,MAAM,yBAAyB,OAAY,OAAe,eAA+B;AACxF,KAAI,SAAS,WAAY,QAAO;CAEhC,MAAM,OAAO,MAAM,QAAQ,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,IAC3D,MAAM,KAAK,KAAK,IAAI,GACpB,MAAM,QAAQ;CAEjB,MAAM,UAAU,MAAM,WAAW;AAEjC,QAAO,QAAQ,QAAQ,EAAE,IAAI,KAAK,IAAI;;AAGvC,MAAM,qBAAqB,MAAe,YAAY,QAAgB;AACrE,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI;EACH,MAAM,MAAM,KAAK,UAAU,KAAK;AAChC,MAAI,IAAI,UAAU,UAAW,QAAO;AAEpC,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
|
3
|
-
import * as effect_Cause0 from "effect/Cause";
|
|
4
4
|
import { ORPCError } from "@orpc/contract";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/errors.d.ts
|
|
7
|
-
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
7
|
+
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
8
8
|
readonly _tag: "PluginRuntimeError";
|
|
9
9
|
} & Readonly<A>;
|
|
10
10
|
declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
@@ -14,7 +14,7 @@ declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
|
14
14
|
readonly cause?: Error;
|
|
15
15
|
readonly retryable: boolean;
|
|
16
16
|
}> {}
|
|
17
|
-
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
17
|
+
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
18
18
|
readonly _tag: "ModuleFederationError";
|
|
19
19
|
} & Readonly<A>;
|
|
20
20
|
declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
@@ -22,7 +22,7 @@ declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
|
22
22
|
readonly remoteUrl: string;
|
|
23
23
|
readonly cause?: Error;
|
|
24
24
|
}> {}
|
|
25
|
-
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
25
|
+
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
26
26
|
readonly _tag: "ValidationError";
|
|
27
27
|
} & Readonly<A>;
|
|
28
28
|
declare class ValidationError extends ValidationError_base<{
|
|
@@ -33,7 +33,13 @@ declare class ValidationError extends ValidationError_base<{
|
|
|
33
33
|
declare const formatORPCError: (error: any) => void;
|
|
34
34
|
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
35
|
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
38
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
39
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
40
|
+
*/
|
|
41
|
+
declare const extractFromFiberFailure: (error: unknown) => unknown;
|
|
36
42
|
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
44
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
39
45
|
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;AAAA,cAEhB,kBAAA,SAA2B,uBAFX,CAAA;;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;EAR9B,SAAA,SAAA,EAAA,MAAmB;EAM1B,SAAA,KAAA,CAAA,EAOY,KAPZ;;cAQA;;;cAEO,eAAA,SAAwB;;;qBAGjB,CAAA,CAAE;;cAgGT;AA3GA,cAgOA,mBA3NK,EAAA,CAAA,IALyB,EAAA,MAAA,EAAA,GAAA,OAAA;AAMrC,cAwOO,aAxOP,EAAA,CAAA,SAAA,EAyOM,SAzON,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,GA6OH,kBA7OG;;;;;;cAiQO;cA2BA,qIAMV"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ORPCError } from "@orpc/contract";
|
|
3
|
+
import { Cause } from "effect";
|
|
3
4
|
import * as effect_Types0 from "effect/Types";
|
|
4
|
-
import * as effect_Cause0 from "effect/Cause";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/errors.d.ts
|
|
7
|
-
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
7
|
+
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
8
8
|
readonly _tag: "PluginRuntimeError";
|
|
9
9
|
} & Readonly<A>;
|
|
10
10
|
declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
@@ -14,7 +14,7 @@ declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
|
14
14
|
readonly cause?: Error;
|
|
15
15
|
readonly retryable: boolean;
|
|
16
16
|
}> {}
|
|
17
|
-
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
17
|
+
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
18
18
|
readonly _tag: "ModuleFederationError";
|
|
19
19
|
} & Readonly<A>;
|
|
20
20
|
declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
@@ -22,7 +22,7 @@ declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
|
22
22
|
readonly remoteUrl: string;
|
|
23
23
|
readonly cause?: Error;
|
|
24
24
|
}> {}
|
|
25
|
-
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
25
|
+
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
26
26
|
readonly _tag: "ValidationError";
|
|
27
27
|
} & Readonly<A>;
|
|
28
28
|
declare class ValidationError extends ValidationError_base<{
|
|
@@ -33,7 +33,13 @@ declare class ValidationError extends ValidationError_base<{
|
|
|
33
33
|
declare const formatORPCError: (error: any) => void;
|
|
34
34
|
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
35
|
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
38
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
39
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
40
|
+
*/
|
|
41
|
+
declare const extractFromFiberFailure: (error: unknown) => unknown;
|
|
36
42
|
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
44
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
39
45
|
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;AAAA,cAEhB,kBAAA,SAA2B,uBAFX,CAAA;;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;EAR9B,SAAA,SAAA,EAAA,MAAmB;EAM1B,SAAA,KAAA,CAAA,EAOY,KAPZ;;cAQA;;;cAEO,eAAA,SAAwB;;;qBAGjB,CAAA,CAAE;;cAgGT;AA3GA,cAgOA,mBA3NK,EAAA,CAAA,IALyB,EAAA,MAAA,EAAA,GAAA,OAAA;AAMrC,cAwOO,aAxOP,EAAA,CAAA,SAAA,EAyOM,SAzON,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,GA6OH,kBA7OG;;;;;;cAiQO;cA2BA,qIAMV"}
|
package/dist/runtime/errors.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ORPCError } from "@orpc/contract";
|
|
2
|
-
import { Data } from "effect";
|
|
2
|
+
import { Cause, Data } from "effect";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/errors.ts
|
|
5
5
|
var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {};
|
|
@@ -165,6 +165,24 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
165
165
|
cause: orpcError
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
170
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
171
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
172
|
+
*/
|
|
173
|
+
const extractFromFiberFailure = (error) => {
|
|
174
|
+
if (!error || typeof error !== "object") return error;
|
|
175
|
+
if ("cause" in error) {
|
|
176
|
+
const cause = error.cause;
|
|
177
|
+
if (cause && typeof cause === "object" && "_tag" in cause) try {
|
|
178
|
+
const squashed = Cause.squash(cause);
|
|
179
|
+
if (squashed instanceof ORPCError) return squashed;
|
|
180
|
+
return squashed;
|
|
181
|
+
} catch {}
|
|
182
|
+
if (cause instanceof ORPCError) return cause;
|
|
183
|
+
}
|
|
184
|
+
return error;
|
|
185
|
+
};
|
|
168
186
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
169
187
|
if (error instanceof ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
170
188
|
if (error instanceof PluginRuntimeError) return error;
|
|
@@ -181,5 +199,5 @@ const toPluginRuntimeError = (error, pluginId, procedureName, operation, default
|
|
|
181
199
|
};
|
|
182
200
|
|
|
183
201
|
//#endregion
|
|
184
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
202
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
185
203
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":["lines: string[]"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC,KAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2C,KAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAA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AA0B,MAAM;AACxD,KAAI,gBACH,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;KAGzC,mBAAkB,UAAU,WADZ,oBAAoB,MAAM,CACK;AAGhD,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,MAAM,CAAC;EAC3E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,MAAM,CAAC;EAC7E,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":["lines: string[]"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n\tif (!error || typeof error !== 'object') return error;\n\t\n\tif ('cause' in error) {\n\t\tconst cause = (error as { cause?: unknown }).cause;\n\t\t\n\t\tif (cause && typeof cause === 'object' && '_tag' in cause) {\n\t\t\ttry {\n\t\t\t\tconst squashed = Cause.squash(cause as Cause.Cause<unknown>);\n\t\t\t\tif (squashed instanceof ORPCError) {\n\t\t\t\t\treturn squashed;\n\t\t\t\t}\n\t\t\t\treturn squashed;\n\t\t\t} catch {\n\t\t\t\t// Not a valid Cause\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (cause instanceof ORPCError) {\n\t\t\treturn cause;\n\t\t}\n\t}\n\t\n\treturn error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC,KAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2C,KAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAAI,MAAM,QAAS,QAAO,MAAM;AAChC,MAAK,MAAc,iBAAiB,MACnC,QAAO,oBAAqB,MAAc,MAAM;;AAIlD,KAAI,iBAAiB,kBAAkB,MAAM,QAAQ,OACpD,QAAO,MAAM,OAAO,KAAI,MAAK,oBAAoB,EAAE,CAAC,CAAC,KAAK,KAAK;AAGhE,KAAI,OAAO,UAAU,YAAY,aAAa,MAC7C,QAAO,OAAQ,MAAc,QAAQ;AAGtC,QAAO,OAAO,MAAM;;AAGrB,MAAM,yBAAyB,OAAY,OAAe,eAA+B;AACxF,KAAI,SAAS,WAAY,QAAO;CAEhC,MAAM,OAAO,MAAM,QAA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