feat: located analyzer-exception diagnostic (XX0000) replacing bare AD0001#366
Merged
Merged
Conversation
Add ALCopsDiagnosticAnalyzer base class plus SafeAnalysisContext and SafeCompilationStartContext decorators that wrap every registered analysis callback in try/catch. An unhandled exception is converted into a located XX0000 diagnostic at the symbol/node being analyzed instead of surfacing as the SDK's AD0001 on app.json line 1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a per-cop XX0000 AnalyzerException diagnostic (Info, enabled), a dedicated
Internal category, resx strings, and a thin {Cop}Analyzer bridge that supplies
the descriptor to the shared ALCopsDiagnosticAnalyzer base. No production
analyzer is converted yet; the scaffolding lets analyzers adopt the harness via
a uniform 3-line change.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Convert CaptionRequired to derive from ApplicationCopAnalyzer, overriding SupportedDiagnosticsCore and InitializeAnalyzer. No Register* call changes. An unhandled exception now surfaces as AC0000 at the analyzed object instead of AD0001 on app.json. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test-only throwing analyzers exercising the symbol, operation (new-hiding), and CompilationStart-nested registration surfaces. Each asserts AC0000 is reported at the analyzed object/line. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add analyzer-exception-harness.instructions.md (design, adoption recipe, SDK-coupling note, fallback) and reference it from analyzer-development, project-overview, and the instruction-maintenance index. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an ALCops analyzer throws (e.g. a
NullReferenceException), the NAV SDK catches it and emits the genericAD0001onapp.jsonline 1 — giving no clue which object/line caused the failure. This PR makes analyzer exceptions diagnosable: they surface as a located per-copXX0000diagnostic (AC0000…TA0000) at the analyzed object/line, with a message naming the failing analyzer and exception.Approach
A reusable harness in
ALCops.Common/Diagnostics/:ALCopsDiagnosticAnalyzer— abstract base. SealsInitialize/SupportedDiagnostics; exposesInitializeAnalyzer(SafeAnalysisContext)+SupportedDiagnosticsCore; auto-appends the cop'sXX0000descriptor.SafeAnalysisContext/SafeCompilationStartContext— decorators that wrap every registered callback in try/catch and reportXX0000at a context-appropriate location.AnalyzerExceptionReporter— builds the diagnostic.{Cop}Analyzerbridge +XX0000descriptor,Internalcategory, and resx strings wired into all 6 cops.Adopting an analyzer is a uniform 3-line edit (no
Register*changes). OnlyCaptionRequired(ApplicationCop) is converted in this PR; the other 92 analyzers adopt incrementally later via the documented recipe.Design notes
Info, enabled — visible, never breaks treat-warnings-as-errors builds.new-hiding (the public params overload routes through internal SDK members); works because adopters type the param asSafeAnalysisContext.Register*in a future SDK is a deliberate compile-time break (forces wrapping the new surface).#ifguards.Tests
Rules/AnalyzerExceptionHarness/adds test-only throwing analyzers covering the symbol, operation (new-hiding), and CompilationStart-nested paths; each assertsAC0000at the expected location. Full suite: 1170 tests pass, all 6 cops build in CI triple-target mode.Docs (separate repo)
XX0000.mdpages + index rows for all 6 cops are prepared on../alcops.devbut not committed here (that repo has unrelated in-progress changes); to be landed via its own PR.Out of scope
CaptionRequiredNRE —AC0000now reveals the culprit.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com