Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error digest from Server Action is not logged server-side #60684

Closed
1 task done
Winwardo opened this issue Jan 15, 2024 · 2 comments · Fixed by #61592
Closed
1 task done

Error digest from Server Action is not logged server-side #60684

Winwardo opened this issue Jan 15, 2024 · 2 comments · Fixed by #61592
Labels
bug Issue was opened via the bug report template. locked

Comments

@Winwardo
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/competent-firefly-9ncwrh?file=%2Fapp%2Fpage.tsx%3A18%2C7

To Reproduce

  1. Make a client side button which calls a server action.
  2. Server action throws an error.
  3. Client catches an error which has a digest.

Current vs. Expected behavior

Client side receives a digest, but this is not logged anywhere (that I can find) on the server.
This means that you can't search the logs for this digest to find out what caused it.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.0.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed), Other (Deployed)

Additional context

When a server action throws an error, in production this is hashed into a digest that is sent to the client. This is a security mechanism that lets developers track errors, without potentially leaking sensitive information like stack-traces to end-users.
This digest is only accessible in the browser.

It would be incredibly helpful if this digest was logged on the server as well. This means the browser could track the error (to say Sentry), and then this can be tied to a server-tracked error too.

Note the documentation explicitly states:

The message property contains a generic message about the error and the digest property contains an automatically generated hash of the error that can be used to match the corresponding error in server-side logs.
https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-server-errors

However, as the digest is not logged on the server, it is not possible to match the corresponding error.

Based on a quick look through the code, I've found this function createErrorHandler might be a reasonable place to incorporate this change.

return stringHash(err.message + err.stack + (err.digest || '')).toString()

I have put together a minimal change that I believe could help here:
https://github.com/Winwardo/next.js/pull/1/files

There is a related issue on React GitHub, where other people would like to pass error codes from the server to client: facebook/react#27362 "[Feature Request]: RSC error - allow error.code or an other specialized prop to be forwarded to the client #27362"

Thanks 👍

@Winwardo Winwardo added the bug Issue was opened via the bug report template. label Jan 15, 2024
@OtisTemler
Copy link

OtisTemler commented Jan 30, 2024

Can confirm, same issue here, no error digest in the log's.
If the server-action explodes and we catch the error, we receive an error digest on the client side and the error is logged to the server console but without the error digest.

huozhi added a commit that referenced this issue Feb 6, 2024
### What

#### Core
This PR respect the error's digest when recieves new error occurred from
server side, and it will be logged into client on production with the
same `digest` property.
If we discover the original RSC error in SSR error handler, retrieve the
original error

#### Tests

* Move the errors related tests from `test/e2e/app-dir/app` to a
separate test suite `test/e2e/app-dir/errors`
* Add a new test case for logging the original RSC error
* Add a new test case for logging the original Server Action error


### Why

This will help associate the `digest` property of the errors logged from
client with the actual generated server errors. Previously they're
different as we might re-compute the digest proper in handler that react
server renderer thinks it's a new error, which causes we have 2
different errors logged on server side, and 1 logged on client side. The
one on client side can associate to the server errors but it's from
react renderer which is not the original error.

Closes NEXT-2094
Fixes #60684
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants