Skip to content

feat: add error code documentation routing#2219

Open
danielroe wants to merge 3 commits intomainfrom
feat/error-code-docs
Open

feat: add error code documentation routing#2219
danielroe wants to merge 3 commits intomainfrom
feat/error-code-docs

Conversation

@danielroe
Copy link
Copy Markdown
Member

@danielroe danielroe commented Mar 27, 2026

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
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
nuxt Ready Ready Preview, Comment Mar 27, 2026 10:20pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

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: a1e2a683-db9e-46a9-b3d9-6686f354abde

📥 Commits

Reviewing files that changed from the base of the PR and between 4f467fc and 397f8ba.

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

📝 Walkthrough

Walkthrough

Updates include a null-safety fix to breadcrumb computation in the docs page, a change to the docs content source fallback repository URL (and an added TODO), a new route rule to prerender /docs/4.x/errors, a server middleware that redirects /docs/errors/*/docs/4.x/errors/*, and a new server route handler that validates short error codes at /e/[code] and redirects to the corresponding /docs/4.x/errors/<code> page.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main purpose of the changeset: adding routing infrastructure for error code documentation.
Description check ✅ Passed The description is related to the changeset, providing context about paired PRs, temporary changes, and preview URLs to test the error routing functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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 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

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.

1 participant