update(docs): next-forms fix unhandled run time error #56600
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
The
zod.parse()
in the example will cause an unexpected run time error. Proposed solve is to usezod.safeParse()
so there won't be an unhandled error exception.Question
: usetry/catch
orsafeParse
?Why?
Example for next-forms will have an unexpected run time error with the current implementation. Changed it so it will be handled through safeParse. So when users are following this portion of the docs they will not encounter an unexpected run time error if they enter an empty string.
How?
parse()
throws an error, and because the server action does not have a top level try/catch to handle the exception, it eventually bubbles up to anUnhandled Runtime Error