[recovery] Return 404 for non-existent story slugs#18783
Draft
pettinarip wants to merge 1 commit into
Draft
Conversation
The stories [slug] route read the markdown file directly in both the page body and generateMetadata without guarding against missing slugs. A crawler probe to /stories/-6/ threw an unhandled ENOENT during generateMetadata, surfacing as a 500 in the Netlify server handler. Mirror the shared [...slug] route: validate the slug against getStorySlugs() and call notFound() in the page, and wrap getMdMetadata in a try/catch that returns basic not-found metadata. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.

Error context
Production error captured from Netlify logs (Grafana → Keep):
/var/task/public/content/stories/-6/index.md(request to/stories/-6/)Root cause
The stories
[slug]route (app/[locale]/stories/[slug]/page.tsx) reads the markdown file directly — in both the page body (getPageData) andgenerateMetadata(getMdMetadata→importMd→fs.readFile) — without guarding against non-existent slugs./stories/hasgenerateStaticParams, but with defaultdynamicParams, unknown slugs like-6(a crawler/bot probe) are rendered on demand.generateMetadatathen throws an unhandledENOENT, surfacing as a 500 in the Netlify server handler instead of a 404.The shared catch-all
[...slug]route already handles this exact case: it validates the path and callsnotFound(), and wrapsgetMdMetadatain a try/catch returning basic not-found metadata. The stories route was written without that guard.Fix
Mirror the catch-all route's handling:
slugagainstgetStorySlugs()and callnotFound()for unknown slugs.generateMetadata: wrapgetMdMetadatain a try/catch that returns basic not-found metadata.Single-file change.
pnpm type-checkpasses and ESLint is clean.Affected files
app/[locale]/stories/[slug]/page.tsx🤖 Generated with Claude Code