Skip to content

feat(docs): serve the Prisma Next error reference, with anchors matching emitted docsUrls - #8125

Merged
ankur-arch merged 2 commits into
mainfrom
claude/prisma-error-reference-docs-19e04f
Aug 4, 2026
Merged

feat(docs): serve the Prisma Next error reference, with anchors matching emitted docsUrls#8125
ankur-arch merged 2 commits into
mainfrom
claude/prisma-error-reference-docs-19e04f

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Every error Prisma Next emits links to its own documentation:

PrismaError [CONTRACT.IDENTIFIER_INVALID]: ...
  docsUrl: https://docs.prisma.io/docs/orm/next/reference/error-reference#CONTRACT.IDENTIFIER_INVALID

Today that URL 404s. After this PR it renders the full error reference (244 codes) and the browser scrolls straight to the CONTRACT.IDENTIFIER_INVALID heading.

The decision

We publish the error reference as a generated page, synced from its canonical source — docs/reference/error-reference.md on prisma/prisma main — and we never hand-edit it here. Upstream CI already guarantees that file documents every code the product ships, so the docs site treats it as an artifact to ingest, not content to maintain.

How it works

The page. apps/docs/scripts/generate-error-reference.mjs converts the upstream markdown into content/docs/orm/next/reference/error-reference.mdx: it adds the frontmatter this site requires, rewrites repo-relative links to GitHub URLs, and refuses input that would break the MDX build (stray braces/JSX, missing or duplicate codes).

The anchors. This is the part most likely to bite. Fumadocs slugifies headings, so ### CONTRACT.IDENTIFIER_INVALID would get the id contractidentifier_invalid — and every emitted docsUrl fragment (raw code: uppercase, with the dot) would silently fail to scroll. The generator therefore appends Fumadocs' explicit-anchor syntax to each code heading:

### CONTRACT.IDENTIFIER_INVALID [#CONTRACT.IDENTIFIER_INVALID]

which makes the element id the raw code text. A new Playwright test (apps/docs/tests/error-reference-anchors.spec.ts) navigates to the fragment URL and asserts the heading has the raw id and lands in the viewport, so a Fumadocs upgrade can't regress this quietly.

Staying current. Two independent mechanisms:

  1. sync-error-reference-docs.yml regenerates the page daily (plus manual and repository_dispatch: error-reference-updated triggers), verifies it, commits as Prismo, and triggers the Vercel deploy hook — the same pattern as the management-API docs sync.
  2. error-reference-check.yml runs upstream's own verifier (list-error-codes.mjs --verify) against the committed page, so even if the sync breaks, drift is caught: on pushes to main, on PRs that touch the page or its tooling, and on a daily schedule.

The generated file is excluded from cspell so upstream wording changes can't fail spellcheck on main.

Looking ahead

When Prisma 8 reaches RC, the ORM next channel becomes v8 and this page moves with it to /docs/orm/v8/reference/error-reference; the product then flips one constant in its docsUrl template.

Alternatives considered

  • Hand-maintained copy in this repo — rejected: 244 codes and growing; it would drift the day after it lands.
  • Fetching the markdown at build time — rejected: every docs build would depend on GitHub being reachable and would not be reproducible. Committing the generated file keeps builds hermetic; the sync workflow owns freshness.
  • Running the drift check on every PR — tried first, walked back after review: an upstream code addition would block unrelated PRs that can't fix it. Path-restricted PR trigger + daily schedule keeps the guarantee without the blast radius.
  • Keeping slugified anchors and mapping fragments in client JS — rejected: the product already ships raw-code fragments; explicit ids are static, testable, and need no runtime code.

🤖 Generated with Claude Code

Serve the canonical error reference from prisma/prisma main at
/docs/orm/next/reference/error-reference. The page is generated by
scripts/generate-error-reference.mjs, which adds an explicit [#CODE]
anchor to every NAMESPACE.SUBCODE heading so the docsUrl fragments the
product emits (raw code, uppercase, with the dot) resolve.

A daily sync workflow regenerates the page from prisma/prisma main, and
a CI check runs list-error-codes.mjs --verify on every push/PR so the
page can never silently miss a shipped code.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview Aug 3, 2026 8:50pm
docs Ready Ready Preview Aug 3, 2026 8:50pm
eclipse Ready Ready Preview Aug 3, 2026 8:50pm
site Ready Ready Preview Aug 3, 2026 8:50pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a generated Prisma error-reference page, a local generator, navigation and spelling configuration, anchor coverage tests, and GitHub Actions workflows that verify and synchronize the documentation.

Changes

Error reference documentation

Layer / File(s) Summary
Generate and publish the error reference
apps/docs/scripts/generate-error-reference.mjs, apps/docs/package.json, apps/docs/content/docs/orm/next/reference/error-reference.mdx, apps/docs/content/docs/orm/next/reference/meta.json, apps/docs/cspell.json
The generator loads and validates source Markdown, adds anchors and frontmatter, rewrites links, and writes the generated MDX page. The page is added to navigation and spelling checks.
Validate generated error-code anchors
apps/docs/tests/error-reference-anchors.spec.ts
The Playwright test checks dotted error-code IDs, heading text, viewport visibility, and broad anchor coverage.
Automate generation and synchronization
.github/workflows/sync-error-reference-docs.yml, .github/workflows/error-reference-check.yml
Workflows generate and verify the page, detect changes, commit and push updates, and trigger a Vercel deployment when documentation changes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant PrismaRepository
  participant DocsRepository
  participant Vercel
  GitHubActions->>PrismaRepository: checkout main source documentation
  GitHubActions->>DocsRepository: run generate:error-reference
  GitHubActions->>DocsRepository: verify error-code completeness
  GitHubActions->>DocsRepository: commit and push changed documentation
  GitHubActions->>Vercel: request deployment hook
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main documentation change and the raw-code anchor behavior described in the pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/prisma-error-reference-docs-19e04f

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.

Comment thread .github/workflows/error-reference-check.yml Fixed
Comment thread .github/workflows/sync-error-reference-docs.yml Fixed
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🍈 Lychee Link Check Report

4 links: ✅ 4 OK | 🚫 0 errors | 🔀 0 redirects | 👻 0 excluded

✅ All links are working!


Full Statistics Table
Status Count
✅ Successful 4
🔀 Redirected 0
👻 Excluded 0
🚫 Errors 0
⛔ Unsupported 0
⏳ Timeouts 0
❓ Unknown 0

@sabbirbaze-lab sabbirbaze-lab left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Md

@argos-ci

argos-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Aug 3, 2026, 8:57 PM

@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: 5

🧹 Nitpick comments (4)
apps/docs/tests/error-reference-anchors.spec.ts (1)

10-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

toHaveText is strict about anchor decoration inside the heading.

Fumadocs heading components often render a child anchor link inside the h3. toHaveText compares the whole normalized text content, so any additional rendered link text makes this assertion fail even though the anchor works. Use toContainText to keep the test focused on the id-to-heading mapping.

♻️ Suggested change
-  await expect(heading).toHaveText("CONTRACT.IDENTIFIER_INVALID");
+  await expect(heading).toContainText("CONTRACT.IDENTIFIER_INVALID");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/tests/error-reference-anchors.spec.ts` around lines 10 - 12, Update
the heading assertion in the error-reference anchor test to use a containment
text check instead of the strict toHaveText check, while preserving the existing
h3 id locator and viewport assertion.
apps/docs/scripts/generate-error-reference.mjs (3)

41-53: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

assertMdxSafe strips only triple-backtick fences.

markdown.replace(/```[\s\S]*?```/g, "") does not handle fences opened with four or more backticks, or tilde fences. If the upstream file adds such a block that contains { or <Tag, the generator throws and blames the source file, even though the content is valid Markdown. Consider matching the fence marker and closing on the same marker length.

♻️ Suggested fence-aware strip
-  const withoutCode = markdown.replace(/```[\s\S]*?```/g, "").replace(/`[^`\n]*`/g, "");
+  const withoutCode = markdown
+    .replace(/^(`{3,}|~{3,})[^\n]*\n[\s\S]*?^\1[^\n]*$/gm, "")
+    .replace(/`[^`\n]*`/g, "");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/scripts/generate-error-reference.mjs` around lines 41 - 53, Update
assertMdxSafe to remove fenced code blocks using a fence-aware pattern that
supports backtick or tilde fences of three or more characters and closes only
with the same marker length; retain the existing inline-code stripping and
hostile-text validation.

105-107: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unhandled top-level rejection produces no actionable output.

await loadSource() at module top level rejects with a bare stack trace when the fetch fails or --source points at a missing file. Wrap the entry point so the script prints the message and exits with a non-zero code. This keeps the sync workflow log readable.

♻️ Suggested entry point
-const { mdx, codeCount } = transform(await loadSource());
-writeFileSync(OUTPUT, mdx);
-console.log(`Wrote ${OUTPUT} with ${codeCount} error codes.`);
+try {
+  const { mdx, codeCount } = transform(await loadSource());
+  writeFileSync(OUTPUT, mdx);
+  console.log(`Wrote ${OUTPUT} with ${codeCount} error codes.`);
+} catch (error) {
+  console.error(error instanceof Error ? error.message : error);
+  process.exit(1);
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/scripts/generate-error-reference.mjs` around lines 105 - 107, Wrap
the top-level generate-error-reference workflow around loadSource, transform,
and writeFileSync in error handling that logs the failure message and sets a
non-zero process exit code. Preserve the successful output and code-count
logging, and ensure failures from both fetching and missing --source files
produce readable actionable output.

67-77: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Do not rewrite code headings inside fenced blocks.

The replace runs while assertMdxSafe(markdown) has already stripped fenced blocks, but other sources could still contain a ### ... line inside a fence. If that happens, Unexpected heading shape or code-spanned anchor text can be emitted. Exclude fenced regions before applying ^### .+$/gm, or update the guard to forbid such source content.

Also confirm Fumadocs emits h3[id="CONTRACT.IDENTIFIER_INVALID"] from the [#CONTRACT.IDENTIFIER_INVALID] suffix, because the Playwright test depends on that custom HTML id.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/scripts/generate-error-reference.mjs` around lines 67 - 77, Update
the heading-rewrite flow around the body.replace call so fenced code-block
contents are excluded before matching or rewriting ### headings, while
preserving code-heading extraction and anchor suffix generation for real
headings. Ensure the resulting Fumadocs output still renders the suffix for a
code heading as h3[id="CONTRACT.IDENTIFIER_INVALID"], and retain the existing
invalid-heading validation outside fenced regions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/error-reference-check.yml:
- Around line 8-12: Restrict the pull_request trigger for the error-reference
check workflow to changes under the documentation path that owns the generated
error reference, while retaining the main push trigger. Update the workflow’s on
configuration near the existing pull_request entry; do not alter the upstream
inspection logic or unrelated triggers.

In @.github/workflows/sync-error-reference-docs.yml:
- Around line 14-18: Add job-level contents: read permissions to the sync job in
.github/workflows/sync-error-reference-docs.yml at lines 14-18 and the verify
job in .github/workflows/error-reference-check.yml at lines 13-17; keep the
existing BOT_TOKEN_DOCS_COMMIT push authentication unchanged.
- Around line 24-29: Prevent checkout credentials from being persisted before
running third-party code: in .github/workflows/sync-error-reference-docs.yml at
lines 24-29, add persist-credentials: false to the prisma/prisma checkout; in
.github/workflows/error-reference-check.yml at lines 18-26, add
persist-credentials: false to both the repository checkout and the prisma/prisma
checkout.
- Around line 55-62: Update the “Commit and push” step to pass the repository
token and branch reference through the step’s env configuration, then reference
those environment variables in the git push command instead of directly
interpolating secrets or github.ref_name in the shell script. Preserve the
existing commit and push behavior.

In `@apps/docs/content/docs/orm/next/reference/error-reference.mdx`:
- Line 14: Update the introductory text for the error-reference page to remove
the repository-internal claims about being the canonical source and CI running
on every PR. In the upstream source for this page, retain only reader-facing
publication and anchor details, or remove the corresponding generated clause in
generate-error-reference.mjs so the published page no longer describes
prisma/prisma internals.

---

Nitpick comments:
In `@apps/docs/scripts/generate-error-reference.mjs`:
- Around line 41-53: Update assertMdxSafe to remove fenced code blocks using a
fence-aware pattern that supports backtick or tilde fences of three or more
characters and closes only with the same marker length; retain the existing
inline-code stripping and hostile-text validation.
- Around line 105-107: Wrap the top-level generate-error-reference workflow
around loadSource, transform, and writeFileSync in error handling that logs the
failure message and sets a non-zero process exit code. Preserve the successful
output and code-count logging, and ensure failures from both fetching and
missing --source files produce readable actionable output.
- Around line 67-77: Update the heading-rewrite flow around the body.replace
call so fenced code-block contents are excluded before matching or rewriting ###
headings, while preserving code-heading extraction and anchor suffix generation
for real headings. Ensure the resulting Fumadocs output still renders the suffix
for a code heading as h3[id="CONTRACT.IDENTIFIER_INVALID"], and retain the
existing invalid-heading validation outside fenced regions.

In `@apps/docs/tests/error-reference-anchors.spec.ts`:
- Around line 10-12: Update the heading assertion in the error-reference anchor
test to use a containment text check instead of the strict toHaveText check,
while preserving the existing h3 id locator and viewport assertion.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2c65851-fd16-4a46-b139-8b033bcf9d84

📥 Commits

Reviewing files that changed from the base of the PR and between 1c91e6f and cce99b3.

📒 Files selected for processing (8)
  • .github/workflows/error-reference-check.yml
  • .github/workflows/sync-error-reference-docs.yml
  • apps/docs/content/docs/orm/next/reference/error-reference.mdx
  • apps/docs/content/docs/orm/next/reference/meta.json
  • apps/docs/cspell.json
  • apps/docs/package.json
  • apps/docs/scripts/generate-error-reference.mjs
  • apps/docs/tests/error-reference-anchors.spec.ts

Comment thread .github/workflows/error-reference-check.yml
Comment thread .github/workflows/sync-error-reference-docs.yml
Comment thread .github/workflows/sync-error-reference-docs.yml
Comment thread .github/workflows/sync-error-reference-docs.yml Outdated
Comment thread apps/docs/content/docs/orm/next/reference/error-reference.mdx Outdated
- Restrict GITHUB_TOKEN to contents: read in both workflows.
- Set persist-credentials: false on all checkouts, including the
  prisma/prisma clone whose script the workflows execute.
- Pass the bot token and target ref through env instead of shell
  interpolation in the sync push step.
- Run the completeness check on relevant-path PRs plus a daily
  schedule instead of every PR, so upstream code additions cannot
  block unrelated PRs while drift on main is still caught daily.
- Reword the generated intro sentence that described the source
  repo's own CI check as if it were this page's.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/docs/scripts/generate-error-reference.mjs`:
- Around line 60-68: Update the replacement text in the body.replace call to use
the upstream CI wording: state that pnpm check:error-reference runs on every
pull request and fails when a production error code is missing, without claiming
documentation is required before shipping. Keep the existing anchor and
canonical-reference context unchanged.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a1629b4-6979-4a44-b6e0-097fb9c3ed29

📥 Commits

Reviewing files that changed from the base of the PR and between cce99b3 and 10a1a70.

📒 Files selected for processing (4)
  • .github/workflows/error-reference-check.yml
  • .github/workflows/sync-error-reference-docs.yml
  • apps/docs/content/docs/orm/next/reference/error-reference.mdx
  • apps/docs/scripts/generate-error-reference.mjs
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/error-reference-check.yml
  • .github/workflows/sync-error-reference-docs.yml
  • apps/docs/content/docs/orm/next/reference/error-reference.mdx

Comment thread apps/docs/scripts/generate-error-reference.mjs
@wmadden-electric

Copy link
Copy Markdown
Contributor Author

@coderabbitai resolve

All findings addressed in 10a1a70: token permissions restricted, persist-credentials disabled on all checkouts, token/ref moved into env, PR trigger path-restricted with a daily schedule, and the generator now rewords the source repo's self-referential intro sentence.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@wmadden-electric Confirmed. I will resolve the addressed findings.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Action performed

Comments resolved and changes approved.

@wmadden-electric wmadden-electric changed the title feat(docs): publish Prisma Next error reference with raw-code anchors feat(docs): serve the Prisma Next error reference, with anchors matching emitted docsUrls Aug 3, 2026
@ankur-arch
ankur-arch merged commit 769523d into main Aug 4, 2026
19 of 20 checks passed
@ankur-arch
ankur-arch deleted the claude/prisma-error-reference-docs-19e04f branch August 4, 2026 08:17
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.

4 participants