fix: improve error messaging for invalid param types in getStaticPaths#94080
Open
AliMahmoudDev wants to merge 1 commit into
Open
fix: improve error messaging for invalid param types in getStaticPaths#94080AliMahmoudDev wants to merge 1 commit into
AliMahmoudDev wants to merge 1 commit into
Conversation
When getStaticPaths receives a non-string value for a regular param or a non-array value for a catchall param, the error message was confusing and didn't clearly indicate what went wrong. This change: - Uses TypeError instead of Error for type mismatches - Changes 'an array' to 'an array of strings' for catchall params - Improves the error message grammar and clarity - Adds a helpful link to the docs Fixes vercel#41281
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
Improves the error message when
getStaticPathsreceives a parameter with an incorrect type (e.g., passing anumberinstead of astringfor a dynamic route param, or passing astringinstead of an array for a catch-all param).Before:
After:
Why?
The original error message was grammatically awkward ("was not provided as a string received number") and used
Errorinstead ofTypeErrorfor what is fundamentally a type mismatch. For catch-all params, it said "an array" instead of "an array of strings", which was imprecise. Issue: #41281How?
ErrortoTypeErrorinpackages/next/src/build/static-paths/pages.tsFixes #41281