MCPcopy
hub / github.com/coder/mux / formatOrpcError

Function formatOrpcError

src/node/orpc/formatOrpcError.ts:300–395  ·  view source on GitHub ↗
(error: unknown, interceptorOptions?: unknown)

Source from the content-addressed store, hash-verified

298}
299
300export function formatOrpcError(error: unknown, interceptorOptions?: unknown): FormattedOrpcError {
301 try {
302 const requestContext = extractRequestContext(interceptorOptions);
303 const where =
304 requestContext.method && requestContext.path
305 ? `${requestContext.method} ${requestContext.path}`
306 : (requestContext.path ?? requestContext.url);
307
308 const whereSuffix = where ? ` ${where}` : "";
309
310 const debugDump: Record<string, unknown> = {
311 request: requestContext,
312 };
313
314 if (error instanceof ORPCError) {
315 const code = typeof error.code === "string" ? error.code : String(error.code);
316 const status = typeof error.status === "number" ? error.status : undefined;
317
318 debugDump.error = {
319 type: "ORPCError",
320 code,
321 status,
322 message: error.message,
323 data: toJsonSafe(error.data, { depth: 6, seen: new WeakSet() }),
324 stack: error.stack,
325 };
326
327 const validation = getValidationErrorInfo(error.cause);
328 if (validation) {
329 debugDump.cause = {
330 type: "ValidationError",
331 message: validation.message,
332 issues: toJsonSafe(validation.issues, { depth: 6, seen: new WeakSet() }),
333 data: toJsonSafe(validation.data, { depth: 6, seen: new WeakSet() }),
334 };
335
336 const lines: string[] = [];
337 lines.push(
338 `ORPC${whereSuffix}: ${code} ${error.message}${
339 status !== undefined ? ` (status ${status})` : ""
340 }`
341 );
342
343 if (validation.issues.length > 0) {
344 const maxIssues = 5;
345 lines.push(`Validation issues (${validation.issues.length}):`);
346
347 for (const issue of validation.issues.slice(0, maxIssues)) {
348 const path = formatIssuePath(issue.path);
349 lines.push(` - ${path}: ${issue.message}`);
350 }
351
352 if (validation.issues.length > maxIssues) {
353 lines.push(` (+${validation.issues.length - maxIssues} more)`);
354 }
355 }
356
357 lines.push(`Data: ${summarizeForLogs(validation.data, 1)}`);

Callers 3

loadServicesFunction · 0.90
createOrpcServerFunction · 0.90

Calls 7

extractRequestContextFunction · 0.85
toJsonSafeFunction · 0.85
getValidationErrorInfoFunction · 0.85
formatIssuePathFunction · 0.85
summarizeForLogsFunction · 0.85
formatUnknownFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected