TkDodo ๐Ÿ”ฎ
TkDodo ๐Ÿ”ฎโ€ข15mo ago

TRPCError that has TRPCError as cause

Having some troubles with error handling, specifically, my errors are double-wrapped in a TRPCError. What I'm doing is basically having a mutation that does:
something: t.procedure
.input(mySchema)
.mutation() => Promise.reject(new Error('oh no'))),
something: t.procedure
.input(mySchema)
.mutation() => Promise.reject(new Error('oh no'))),
and then, the onError handler has:
onError({ error }) {
console.log('onError', error.name, error.cause.name)
},
onError({ error }) {
console.log('onError', error.name, error.cause.name)
},
which logs: onError TRPCError TRPCError. If I then go further with error.cause.cause.name, I can see my error. I already tried to reproduce this in isolation, but in a sandbox, I get: onError TRPCError Error, which is what I would expect. Just wanted to know if anyone has seen something similar; Not sure how this can happen ... thanks
4 Replies
Alex / KATT ๐Ÿฑ
Alex / KATT ๐Ÿฑโ€ข15mo ago
hmmmm this is weird
Alex / KATT ๐Ÿฑ
Alex / KATT ๐Ÿฑโ€ข15mo ago
GitHub
Setting TRPCError.name to "TRPCError" by dios-david ยท Pull Request ...
๐ŸŽฏ Changes Setting this.name to "TRPCError" in the TRPCError constructor instead of using this.constructor.name. Background I ran into an issue with my trpc server where the production bui...
Alex / KATT ๐Ÿฑ
Alex / KATT ๐Ÿฑโ€ข15mo ago
i'll try to push that try upgrading to 10.38.5
TkDodo ๐Ÿ”ฎ
TkDodo ๐Ÿ”ฎOPโ€ข14mo ago
yeah that fixes it. Thank you so much ๐Ÿ™ I'm not quite sure why I couldn't reproduce it in isolation though