Skip to content

fix: improve error messaging for invalid param types in getStaticPaths#94080

Open
AliMahmoudDev wants to merge 1 commit into
vercel:canaryfrom
AliMahmoudDev:fix/improve-getstaticpaths-error-message
Open

fix: improve error messaging for invalid param types in getStaticPaths#94080
AliMahmoudDev wants to merge 1 commit into
vercel:canaryfrom
AliMahmoudDev:fix/improve-getstaticpaths-error-message

Conversation

@AliMahmoudDev
Copy link
Copy Markdown

What?

Improves the error message when getStaticPaths receives a parameter with an incorrect type (e.g., passing a number instead of a string for a dynamic route param, or passing a string instead of an array for a catch-all param).

Before:

Error: A required parameter (id) was not provided as a string received number in getStaticPaths for /[id]

After:

TypeError: A required parameter (id) was not provided as a string in getStaticPaths for /[id]. Received number. See: https://nextjs.org/docs/messages/invalid-getstaticpaths-value

Why?

The original error message was grammatically awkward ("was not provided as a string received number") and used Error instead of TypeError for what is fundamentally a type mismatch. For catch-all params, it said "an array" instead of "an array of strings", which was imprecise. Issue: #41281

How?

  • Changed Error to TypeError in packages/next/src/build/static-paths/pages.ts
  • Changed error message for catch-all params from "an array" to "an array of strings"
  • Improved the message grammar (separated clauses with periods)
  • Added a helpful link to the docs
  • Updated existing test expectations to match the new message format

Fixes #41281

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Error Messaging / Handling in getStaticPaths

1 participant