refactor: remove TRPCError handling from getServerErrorFromUnknown (#25691)

* refactor: remove TRPCError handling from getServerErrorFromUnknown

This removes the @trpc/server dependency from packages/lib by removing
TRPCError handling from getServerErrorFromUnknown.ts.

packages/lib is meant to be a general utility library that other packages
depend on, so it shouldn't import tRPC. The callers that need to handle
TRPCError (like onErrorHandler.ts and defaultResponder.ts) already handle
it explicitly before calling getServerErrorFromUnknown, so this change
has no behavioral impact.

Changes:
- Remove TRPCError and getHTTPStatusCodeFromError imports
- Remove TRPCError instanceof check from getServerErrorFromUnknown
- Update docstring to note that TRPCError is not handled
- Remove TRPCError-related tests (they belong in the tRPC layer)
- Fix lint warnings in Prisma error tests (replace 'as any' with proper type)

Co-Authored-By: [email protected] <[email protected]>

* wip

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Benny JooandDevin AI authored and GitHub committed 2025-12-09 16:21:55 -03:00
1 parent be12ac75b4
commit 529ca159f7
3 files changed
+28 -52

No files matched your search

@@ -1,11 +1,9 @@
import { Prisma } from "@calcom/prisma/client";
import { describe, expect, test } from "vitest";
import { ZodError } from "zod";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { ErrorWithCode } from "@calcom/lib/errors";
import { TRPCError } from "@trpc/server";
import { Prisma } from "@calcom/prisma/client";
import { HttpError } from "../http-error";
import { TracedError } from "../tracing/error";
@@ -156,42 +154,6 @@ describe("TracedError handling", () => {
});
});
describe("TRPCError handling", () => {
test("should handle TRPCError with BAD_REQUEST", () => {
const trpcError = new TRPCError({
code: "BAD_REQUEST",
message: "Invalid input data",
});
const result = getServerErrorFromUnknown(trpcError);
expect(result.statusCode).toBe(400);
expect(result.message).toBe("Invalid input data");
expect(result.data).toBeUndefined();
});
test("should handle TracedError wrapping TRPCError", () => {
const trpcError = new TRPCError({
code: "NOT_FOUND",
message: "Resource not found",
});
const tracedData = { resourceId: "789" };
const traceContext = {
traceId: "trace_trpc123",
spanId: "span_trpc123",
operation: "resource_lookup",
};
const tracedError = new TracedError(trpcError, traceContext, tracedData);
const result = getServerErrorFromUnknown(tracedError);
expect(result.statusCode).toBe(404);
expect(result.message).toBe("Resource not found");
expect(result.data).toEqual({ ...tracedData, traceId: traceContext.traceId });
});
});
describe("ZodError handling", () => {
test("should handle ZodError with validation issues", () => {
const zodError = new ZodError([