Skip to content

feat: add error code documentation routing#2219

Open
danielroe wants to merge 4 commits into
mainfrom
feat/error-code-docs
Open

feat: add error code documentation routing#2219
danielroe wants to merge 4 commits into
mainfrom
feat/error-code-docs

Conversation

@danielroe

@danielroe danielroe commented Mar 27, 2026

Copy link
Copy Markdown
Member

paired with nuxt/nuxt#34719

Note

The content.config.ts change pointing docsV4Source to feat/error-context is temporary for preview purposes. It must be reverted to 4.x before merging.

Preview URLs to test

  • /e/NUXT_E1001 → should redirect to error page
  • /docs/errors/E1001 → should redirect to versioned error page
  • /docs/4.x/errors/E1001 → should render the error doc
  • /docs/4.x/errors → should render the error codes index

@vercel

vercel Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuxt Error Error Jun 24, 2026 12:59pm

@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66a1f681-c569-4ccb-b842-667dee7ac363

📥 Commits

Reviewing files that changed from the base of the PR and between 9e78ce3 and 6db7b63.

📒 Files selected for processing (4)
  • content.config.ts
  • nuxt.config.ts
  • server/middleware/error-docs-redirect.ts
  • server/routes/e/[code].get.ts
✅ Files skipped from review due to trivial changes (1)
  • nuxt.config.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/middleware/error-docs-redirect.ts
  • server/routes/e/[code].get.ts
  • content.config.ts

📝 Walkthrough

Walkthrough

Two new server-side handlers are added. A middleware (server/middleware/error-docs-redirect.ts) intercepts requests matching /docs/errors/<rest> and issues a 302 redirect to /docs/4.x/errors/<rest> with the path segment lowercased. A GET route handler (server/routes/e/[code].get.ts) accepts short URLs in the form NUXT_E#### or NUXT_B####, validates the code against a regex, throws a 404 for invalid codes, and redirects valid codes to /docs/4.x/errors/<derivedCode>. In nuxt.config.ts, a prerender rule is added for /docs/4.x/errors. In content.config.ts, the docsV4Source.repository fallback URL is changed from the 4.x branch to the nostics-errors branch, with a TODO comment added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding routing for error-code documentation.
Description check ✅ Passed The description is related to the PR and describes the error-code routing and preview paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/error-code-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/middleware/error-docs-redirect.ts (1)

11-16: Consider tightening the regex to match only valid error code formats.

The current regex (.+) is very permissive and will redirect any path under /docs/errors/ to the versioned path, even invalid ones like /docs/errors/foo or paths with extra segments. While this won't cause security issues (it just results in 404s), it's inconsistent with the strict validation in server/routes/e/[code].get.ts.

For consistency with the route handler and clearer intent, consider restricting to the expected error code format:

♻️ Optional: Align regex with expected error code format
-  // Match /docs/errors/... but NOT /docs/3.x/errors/... or /docs/4.x/errors/...
-  const match = path.match(/^\/docs\/errors\/(.+)$/)
+  // Match /docs/errors/E1001 or /docs/errors/B1001 (E or B followed by digits)
+  const match = path.match(/^\/docs\/errors\/([EB]\d+)$/)

Alternatively, if the permissive approach is intentional to gracefully handle future formats, the current implementation is acceptable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/middleware/error-docs-redirect.ts` around lines 11 - 16, The current
permissive regex in the error-docs redirect (the path.match call) allows any
segment under /docs/errors/ to be redirected; change it to validate only the
expected error-code format used by server/routes/e/[code].get.ts (e.g.,
three-digit codes with optional slug/segment patterns) before calling
sendRedirect(event, `/docs/4.x/errors/${match[1]}`, 302). Update the path.match
expression to mirror the same pattern used by the route handler so only valid
error codes are redirected and everything else is ignored.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@content.config.ts`:
- Around line 13-14: The repo fallback currently points to the feature branch
'https://github.com/nuxt/nuxt/tree/feat/error-context' when
process.env.NUXT_V4_PATH is not set; change this so the default does not
reference a feature branch by replacing that URL with the stable
'https://github.com/nuxt/nuxt/tree/4.x' (or set repository to undefined and
require an explicit env var to opt into the feature branch), updating the
`repository` assignment that references process.env.NUXT_V4_PATH to ensure
previews are only selected via an explicit environment variable rather than
defaulting to the feat/error-context branch.

---

Nitpick comments:
In `@server/middleware/error-docs-redirect.ts`:
- Around line 11-16: The current permissive regex in the error-docs redirect
(the path.match call) allows any segment under /docs/errors/ to be redirected;
change it to validate only the expected error-code format used by
server/routes/e/[code].get.ts (e.g., three-digit codes with optional
slug/segment patterns) before calling sendRedirect(event,
`/docs/4.x/errors/${match[1]}`, 302). Update the path.match expression to mirror
the same pattern used by the route handler so only valid error codes are
redirected and everything else is ignored.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2035a71d-eb5e-47ec-8126-fb12bc66cde1

📥 Commits

Reviewing files that changed from the base of the PR and between 9baba17 and b469918.

📒 Files selected for processing (5)
  • app/pages/docs/[...slug].vue
  • content.config.ts
  • nuxt.config.ts
  • server/middleware/error-docs-redirect.ts
  • server/routes/e/[code].get.ts

Comment thread content.config.ts Outdated
Comment on lines +13 to +14
// TODO: revert to 4.x branch before merging
repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/feat/error-context' : undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid shipping a feature-branch fallback for v4 docs source.

Line 14 points to feat/error-context, and with default envs this becomes the effective source. That’s risky for merge/release because it can drift or break when the feature branch changes. Please revert the fallback to 4.x before merge (or gate preview branch selection behind an explicit env var).

Suggested fix
 const docsV4Source = {
   cwd: process.env.NUXT_V4_PATH ?? undefined,
-  // TODO: revert to 4.x branch before merging
-  repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/feat/error-context' : undefined,
+  repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/4.x' : undefined,
   include: 'docs/**/*',
   exclude: ['docs/**/*.json'],
   prefix: '/docs/4.x'
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: revert to 4.x branch before merging
repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/feat/error-context' : undefined,
const docsV4Source = {
cwd: process.env.NUXT_V4_PATH ?? undefined,
repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/4.x' : undefined,
include: 'docs/**/*',
exclude: ['docs/**/*.json'],
prefix: '/docs/4.x'
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@content.config.ts` around lines 13 - 14, The repo fallback currently points
to the feature branch 'https://github.com/nuxt/nuxt/tree/feat/error-context'
when process.env.NUXT_V4_PATH is not set; change this so the default does not
reference a feature branch by replacing that URL with the stable
'https://github.com/nuxt/nuxt/tree/4.x' (or set repository to undefined and
require an explicit env var to opt into the feature branch), updating the
`repository` assignment that references process.env.NUXT_V4_PATH to ensure
previews are only selected via an explicit environment variable rather than
defaulting to the feat/error-context branch.

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.

2 participants