- config.ts: Convert arrow functions to function declarations - api-client.ts: Extract duplicated RPCLink logic into buildClient helper - format-error.ts: Add centralized ORPCError handling - complete-login.ts: Remove redundant error handling (now in formatError) - status.ts: Simplify formatRelativeTime, improve whitespace - create.ts: Rename validRoles to VALID_ROLES, add as const, early return - completions.ts: Derive Shell type from SUPPORTED_SHELLS array Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
21 lines
688 B
TypeScript
21 lines
688 B
TypeScript
import { ORPCError } from "@orpc/client";
|
|
|
|
/**
|
|
* Format an unknown error value into a string message.
|
|
* Handles ORPCError, Error instances, strings, and other types safely.
|
|
*/
|
|
export function formatError(error: unknown): string {
|
|
if (error instanceof ORPCError) {
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- ORPCError.code is typed as any
|
|
return `[${error.code}] ${error.message}`;
|
|
}
|
|
if (error instanceof Error) {
|
|
return error.message;
|
|
}
|
|
if (typeof error === "string") {
|
|
return error;
|
|
}
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- intentional unknown coercion
|
|
return `${error}`;
|
|
}
|