trpc-openapi
trpc-openapi copied to clipboard
All TRPCErrors thrown are wrapped by INTERNAL_SERVER_ERRORs when building with `esbuild`
Hi, I am using esbuild
v0.17.4 to build and bundle the TRPC server-side code. By default, esbuild
minification mangles the names of functions and properties, leading this condition to fail:
https://github.com/jlalmes/trpc-openapi/blob/aea45441af785518df35c2bc173ae2ea6271e489/src/adapters/node-http/errors.ts#L20
... which results in all TRPCErrors being wrapped INTERNAL_SERVER_ERRORs.
Is there some nuance that makes this alternative incorrect?
if (cause instanceof TRPCError) {
return cause as TRPCError;
}
A workaround is to set keepNames
to true
in the esbuild
build options (see https://esbuild.github.io/api/#keep-names).
This line was copied over from tRPC main repo, do you have the same issue there?
https://github.com/trpc/trpc/blob/6b9193ea450349f85c5305514b89674def72e442/packages/server/src/internals/errors.ts#L17-L33
I suspect I would, but I am only using TRPC with OpenAPI at the moment. I will put a little test case together without trpc-openapi when I get a chance.
Sorry I never got around to a repro, but I did notice that a relevant patch of code was changed upstream and merged in trpc v10.38.5 (PR) - specifically by hardcoding TRPCError.name to 'TRPCError'.