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

[Flight] Serialize Error Values #31104

Merged
merged 1 commit into from
Sep 30, 2024
Merged

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Sep 30, 2024

The idea is that the RSC protocol is a superset of Structured Clone. #25687 One exception that we left out was serializing Error objects as values. We serialize "throws" or "rejections" as Error (regardless of their type) but not Error values.

This fixes that by serializing Error objects. We don't include digest in this case since we don't call onError and it's not really expected that you'd log it on the server with some way to look it up.

In general this is not super useful outside throws. Especially since we hide their values in prod. However, there is one case where it is quite useful. When you replay console logs in DEV you might often log an Error object within the scope of a Server Component. E.g. the default RSC error handling just console.error and error object.

Before this would just be an empty object due to our lax console log serialization:
Screenshot 2024-09-30 at 2 24 03 PM
After:
Screenshot 2024-09-30 at 2 36 48 PM

TODO for a follow up: Flight Reply direction. This direction doesn't actually serialize thrown errors because they always reject the serialization.

Copy link

vercel bot commented Sep 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 6:51pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 30, 2024
@react-sizebot
Copy link

react-sizebot commented Sep 30, 2024

The size diff is too large to display in a single comment. The GitHub action for this pull request contains an artifact called 'sizebot-message.md' with the full message.

Generated by 🚫 dangerJS against 775defa

@eps1lon
Copy link
Collaborator

eps1lon commented Sep 30, 2024

Does this also work for Actions that return error objects e.g. during form validation?

@sebmarkbage
Copy link
Collaborator Author

sebmarkbage commented Sep 30, 2024

Yes. But not very useful since its message will be hidden in prod.

@sebmarkbage sebmarkbage merged commit 326832a into facebook:main Sep 30, 2024
184 checks passed
@sophiebits
Copy link
Contributor

Will people write code that does that in dev and then be sad when it breaks in prod?

@eps1lon
Copy link
Collaborator

eps1lon commented Oct 1, 2024

Will people write code that does that in dev and then be sad when it breaks in prod?

We got this feedback already for thrown errors from Server Actions. @gnoff mentioned that we always want to include a notice in the error message that it'll be stripped in prod to prevent relying on messages for prod behavior.

But we didn't follow-up. Might worth bringing this up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants