Skip to content

feat(errors): structured Q-15-1 diagnostic for duplicate crossref identifiers (bd-rr6qzcvu)#321

Merged
cscheid merged 2 commits into
mainfrom
feature/bd-rr6qzcvu-crossref-dup-id-diagnostic
Jun 22, 2026
Merged

feat(errors): structured Q-15-1 diagnostic for duplicate crossref identifiers (bd-rr6qzcvu)#321
cscheid merged 2 commits into
mainfrom
feature/bd-rr6qzcvu-crossref-dup-id-diagnostic

Conversation

@cscheid

@cscheid cscheid commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

A duplicate crossref identifier (e.g. two cells both #| label: fig-charts) was reported as a bare, code-less, span-less line:

Error: duplicate crossref identifier `fig-charts`

It rendered as plain text only because to_text gates the ariadne box on has_any_location, and the diagnostic carried no location — even though duplicate_id_diagnostic already received both occurrences' SourceInfo and discarded them with a TODO.

This PR (two staged commits) wires the spans through and clears the real instance.

Stage 1 — the structured diagnostic

  • New crossref subsystem (number 15) + code Q-15-1 "Duplicate Crossref Identifier" in the catalog.
  • duplicate_id_diagnostic rebuilt with DiagnosticMessageBuilder: with_code + with_location(second) (underlines the duplicate) + add_detail_at("first defined here", first) + problem + hint. Still error-level.
  • Docs page docs/errors/crossref/Q-15-1.qmd (new crossref/ subsystem dir).
  • Refreshed the stale CONTRIBUTING-ERRORS.md subsystem table (12–15).

The diagnostics already flow ctx.diagnostics → render_output.diagnostics, rendered against the document's source context, so the located form renders with ariadne automatically:

Error: [Q-15-1] Duplicate crossref identifier
   ╭─[ dup.qmd:9:1 ]
 5 │ ![First chart](a.png){#fig-charts}    ── first defined here
 9 │ ![Second chart](b.png){#fig-charts}   ── The crossref identifier `fig-charts` is defined more than once. …
  ℹ Give one of the targets a different `label:` (or `#id`).

On the real docs/ render the diagnostic spans both multi-line code cells in figures.qmd.

Stage 2 — clear the instance

The "Subcaptions" example in figures.qmd showed the same figure in a Jupyter tab and a Knitr tab, both labeled fig-charts → a duplicate id in the rendered DOM. Relabeled to fig-charts-jupyter / fig-charts-knitr. No @fig-charts reference exists anywhere in docs/, so nothing else changes. q2 render docs/ goes from 1 error, 27 warnings to 27 warnings (no error).

Tests

  • Catalog presence test for Q-15-1 (subsystem crossref).
  • Transform test duplicate_id_diagnostic_is_coded_and_located: code + primary location + a located detail.

Verification

  • cargo nextest run --workspace — 10,289 passed.
  • cargo xtask verify (Rust + WASM + hub-client) — all steps passed.
  • End-to-end: minimal fixture and the real docs/ render both show the boxed [Q-15-1] underlining both sites; after the relabel, docs/ renders with 0 errors.

Follows the same pattern as #318 (Q-5-6/Q-5-7 resource-copy diagnostics).

Plan: claude-notes/plans/2026-06-19-crossref-duplicate-id-diagnostic.md

🤖 Generated with Claude Code

cscheid and others added 2 commits June 22, 2026 10:57
…ntifiers (bd-rr6qzcvu, stage 1)

A duplicate crossref id (e.g. two cells both `#| label: fig-charts`) was
reported as a bare, code-less, span-less line: `Error: duplicate crossref
identifier <id>`. It rendered as plain text only because `to_text` gates the
ariadne box on `has_any_location`, and the diagnostic carried no location.

`duplicate_id_diagnostic` already *received* both occurrences' `SourceInfo`
(the first, from the index, and the duplicate) and discarded them with a TODO.
This wires them through:

- New `crossref` subsystem (number 15) + code `Q-15-1` "Duplicate Crossref
  Identifier" in the catalog.
- `duplicate_id_diagnostic` rebuilt with `DiagnosticMessageBuilder`:
  `.with_code("Q-15-1")`, `.with_location(second)` (underlines the duplicate),
  `.add_detail_at("first defined here", first)`, a problem statement, and a
  hint. Still error-level — duplicate ids are genuinely ambiguous.
- Docs page `docs/errors/crossref/Q-15-1.qmd` (new `crossref/` subsystem dir).
- Refreshed the stale `CONTRIBUTING-ERRORS.md` subsystem table (12–15).

The diagnostics already flow `ctx.diagnostics -> render_output.diagnostics`,
rendered against the document's source context, so the located form renders
with ariadne automatically — confirmed end-to-end:

  Error: [Q-15-1] Duplicate crossref identifier
   ╭─[ dup.qmd:9:1 ]
 5 │ ![First chart](a.png){#fig-charts}      ── first defined here
 9 │ ![Second chart](b.png){#fig-charts}     ── The crossref identifier `fig-charts` is defined more than once. …
  ℹ Give one of the targets a different `label:` (or `#id`).

On the real `docs/` render the `figures.qmd` tabset duplicate now renders the
same boxed, multi-line diagnostic across both code cells.

Tests:
- Catalog presence test for Q-15-1 (subsystem `crossref`).
- Transform test `duplicate_id_diagnostic_is_coded_and_located`: code + primary
  location + a located detail.

This is **stage 1** of bd-rr6qzcvu (the diagnostic). Stage 2 relabels the two
`fig-charts` cells in figures.qmd to clear the error itself — deliberately left
for a follow-up so the improved message can be seen on a real render.

Verified: `cargo nextest run --workspace` (10,289 passed) and full
`cargo xtask verify` green.

Plan: claude-notes/plans/2026-06-19-crossref-duplicate-id-diagnostic.md

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-rr6qzcvu, stage 2)

The "Subcaptions" example in docs/guides/authoring/figures.qmd shows the same
figure in a Jupyter tab and a Knitr tab, both labeled `#| label: fig-charts`.
Because both panels live in the rendered DOM, the two cells produce a duplicate
`fig-charts` id — the Q-15-1 error surfaced in stage 1.

Relabel them `fig-charts-jupyter` / `fig-charts-knitr` so each is unique. No
`@fig-charts` reference exists anywhere in docs/, so nothing else changes.

`q2 render docs/` now reports `Rendered 169 of 169 files — 27 warnings`
(was `1 error, 27 warnings`); the Q-15-1 error is gone. The remaining warnings
are pre-existing Q-5-6 (missing images) and Q-13-4 (body links).

Plan: claude-notes/plans/2026-06-19-crossref-duplicate-id-diagnostic.md

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cscheid cscheid merged commit 5046429 into main Jun 22, 2026
5 checks passed
@cscheid cscheid deleted the feature/bd-rr6qzcvu-crossref-dup-id-diagnostic branch June 22, 2026 16:22
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