You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: FormData normalization errors in nextAppDirCaller leak as raw TypeError and skip onError #8124
When a Next.js server action is created with experimental_caller(nextAppDirCaller(...)) and normalizeFormData is on (the default), the submitted FormData is converted with formDataToObject before the procedure runs. That conversion throws on ordinary field names —
for example a form with both user and user.name, because one key is treated as a string and
the other as an object.
In nextAppDirCaller, the conversion runs before the invoke(...).catch(handleError) chain, so
when it throws:
a raw internal TypeError leaks to the caller instead of a TRPCError,
the onError handler is never called,
rethrowNextErrors is never called.
The other caller of the same helper (packages/next/src/app-dir/server.ts) already wraps it in
try/catch and raises a TRPCError, so the two code paths are inconsistent.
Expected: a TRPCError (INTERNAL_SERVER_ERROR), with onError called, like the other path.
import{initTRPC}from'@trpc/server';import{nextAppDirCaller}from'@trpc/server/adapters/next-app-dir';constt=initTRPC.create();constaction=t.procedure.experimental_caller(nextAppDirCaller({onError: (o)=>console.log('onError',o.error.code)}),).mutation(()=>'ok');constfd=newFormData();fd.set('user','alice');fd.set('user.name','bob');awaitaction(fd);// Throws: TypeError: Cannot create property 'name' on string 'alice'// onError is never logged. Expected a TRPCError and onError to fire.
Additional information
Root cause: in packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts the formDataToObject(input) call is outside the try/catch that handleError provides. I have a fix
and a regression test ready.
👨👧👦 Contributing
🙋♂️ Yes, I'd be down to file a PR fixing this bug!
Confirmed on current main: in packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts, the mutation branch calls formDataToObject(input) before the opts.invoke(...).catch(handleError(input)) chain, so a throw there escapes as a raw TypeError and skips both onError and rethrowNextErrors. The other caller of the same helper, packages/next/src/app-dir/server.ts:163-170, already wraps it and raises a TRPCError.
The conversion itself fails when a field name is both a prefix and a leaf: set() assigns a string at user, then the next entry walks into it as if it were an object.
Plan:
Move the conversion inside the invoke chain for the mutation branch so the existing handleError handles it, which also keeps onError and rethrowNextErrors working.
Leave query and the other caller alone.
Add regression tests for a user + user.name form: the caller rejects with TRPCError and onError runs with the converted input.
@Manan1801 has #8126 open for this, so I am stepping back rather than competing with it. Their patch takes the same approach I had and is the better one: it reuses the "Failed to convert FormData to an object" message, which keeps the two formDataToObject callers saying the same thing.
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.
Activity
lx3133584 commentedon Nov 18, 2026
Claim.
Confirmed on current main: in
packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts, themutationbranch callsformDataToObject(input)before theopts.invoke(...).catch(handleError(input))chain, so a throw there escapes as a rawTypeErrorand skips bothonErrorandrethrowNextErrors. The other caller of the same helper,packages/next/src/app-dir/server.ts:163-170, already wraps it and raises aTRPCError.The conversion itself fails when a field name is both a prefix and a leaf:
set()assigns a string atuser, then the next entry walks into it as if it were an object.Plan:
mutationbranch so the existinghandleErrorhandles it, which also keepsonErrorandrethrowNextErrorsworking.queryand the other caller alone.user+user.nameform: the caller rejects withTRPCErrorandonErrorruns with the converted input.lx3133584 commentedon Nov 18, 2026
@Manan1801 has #8126 open for this, so I am stepping back rather than competing with it. Their patch takes the same approach I had and is the better one: it reuses the
"Failed to convert FormData to an object"message, which keeps the twoformDataToObjectcallers saying the same thing.fix(server): route FormData normalization errors through onError in n…
github-actions commentedon Nov 24, 2026
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.