Replies: 2 comments
-
Hi, What you’re experiencing is related to how errors thrown from server actions are handled in the Next.js/React Server Actions framework. When an error is thrown inside a server action and caught on the client side (e.g., with try/catch or .catch()), the original error stack or message might not be fully preserved or logged as you expect. Instead, the error often gets serialized and re-thrown across the client-server boundary, which can cause console.error to show less or no output. Some points to consider: Error Serialization React/Next.js Error Handling Asynchronous Context Workaround suggestions: On the client side, log the caught error but also inspect other properties (e.g., err.message, err.stack, or even the raw response if available). Use dedicated error reporting or monitoring tools to capture errors on the server side. This behavior is a known quirk in frameworks that blur the server-client boundary with async server actions, and improvements may come as the feature matures. |
Beta Was this translation helpful? Give feedback.
-
This behavior happens because of how React Server Actions and Next.js handle errors and logging during server-client communication. When you call console.error inside a client component that catches an error thrown from a server action, the error object you receive is often a serialized or proxied version, not the original error. This means the error’s stack trace or message properties might not be fully accessible or logged properly in the client console. Additionally, React's server actions run on the server, and their logs appear in the server-side console (e.g., terminal or cloud logs), not the browser console. So if you do console.error inside the server action itself, that output goes to the server logs, not the client. When you catch that error on the client and log it with console.error, you might get an empty or less informative object because:
To debug better:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
any call to
console.error(...)
that includes the reference trhow by a call to a server action (as caught bytry/catch
when usingawait
or.catch()
, disappears!here's a working minimal test case started from the latest version https://github.com/gcb/react_test_case_useActionState/blob/main/app/server-action-client.tsx#L27-L31
(
myServerActionDenied()
will return a 403, and trigger thecatch(err)
)Beta Was this translation helpful? Give feedback.
All reactions