Skip to content

Refuse a diagnostic catalogue the built-in descriptors weren't allocated from [patch] - #70

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/check-diagnostic-catalog-58
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/check-diagnostic-catalog-58

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #58

GeneratorBase.Diagnostics was abstract but nothing read it. A generator could return null, or a catalogue with a different prefix from its MetadataFileMissing / MetadataParseFailed descriptors, and nothing caught the mismatch. That is exactly the prefix drift DiagnosticCatalog exists to prevent.

Change

This is option (a), as the triage recommends. Initialize now checks first that Diagnostics is non-null and that both built-in descriptors are among its Descriptors (matched by ID). If either check fails, it throws InvalidOperationException naming the generator, the member, the descriptor ID, the catalogue's category, and the IDs the catalogue actually holds. The Roslyn driver turns that into its CS8784 warning, and the generator emits nothing.

The XML docs on Diagnostics and the README property table now state the requirement.

Behaviour note for consumers: a generator whose two built-in descriptors come from a catalogue other than the one it names will now stop generating, where before it generated silently. That is the intent of the issue. Every test generator in this repository already complies.

Tests

  • ANullDiagnosticCatalogueIsRefused
  • ADescriptorFromAnotherCatalogueIsRefused: the generator names an OTH catalogue while its descriptors are TST001/TST002. The test checks that the message names MetadataFileMissing (TST001) and the 'Other' catalogue.
  • Both fail with the EnsureCataloged() call removed and pass with it. The full suite passes (82 tests).

Generated by Claude Code

…ted from [patch]

GeneratorBase required a Diagnostics catalogue but never read it, so a null
catalogue, or one with a different prefix from the MetadataFileMissing and
MetadataParseFailed descriptors, was silently accepted. Initialize now
checks that both descriptors are in the catalogue and throws an
InvalidOperationException naming the descriptor and the catalogue otherwise.

Fixes #58

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3R5YfaNjqL9oXpRg6
@sonarqubecloud

sonarqubecloud Bot commented Nov 7, 2026

Copy link
Copy Markdown

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.

GeneratorBase.Diagnostics must be overridden but is never read, so a null or wrong-prefix catalogue is silently accepted

2 participants