Fix crash when toc references a missing file#3469
Conversation
A `toc` entry pointing at a Markdown file that doesn't exist on disk caused the navigation builder to leave the root node's `Index` as a `null!` sentinel. `BuildNavigationLookups` (and `VisitNavigation` with extensions enabled) then dereferenced that sentinel via the covariant `INodeNavigationItem<IDocumentationFile, ...>` branch, throwing an unhandled `NullReferenceException` before the already-computed validation error could surface. Guard the null `Index` sentinel at both dereference sites so the build exits cleanly and reports the error. Also clarify the diagnostic to state whether the referenced file is missing on disk or not a valid Markdown document, anchored to the docset.yml location. Closes #3245 Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR fixes a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
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. Comment |
Why
Running
docs-builder build/serveon a docset whosetocreferences a Markdown file that doesn't exist on disk crashed with an unhandledNullReferenceExceptionwhile building navigation lookups, instead of reporting a clear validation error. The validation error was actually already computed — the process just died on an unguarded null dereference before it could be shown.Closes #3245.
What
When a TOC entry resolves to a file the factory can't create, that nav item is dropped. If a node ends up with zero items, its
Indexis set to anull!sentinel. BecauseINodeNavigationItem<out TIndex, …>is covariant, the root node matches theINodeNavigationItem<IDocumentationFile, …>branch in bothBuildNavigationLookupsandDocumentationSet.VisitNavigation, whereIndex.Modelwas dereferenced unconditionally → the reported NRE.This change:
Indexsentinel at both dereference sites, so the build no longer crashes and the already-emitted validation error surfaces, exiting cleanly.docset.ymllocation.Navigation.Testscase that drivesBuildNavigationLookupswith a missing-file TOC and asserts it does not throw and emits a clear error (the existing validation tests never exercised this path).Verified end-to-end: a docset with a missing
file:entry now printsTable of contents references '…' but the file does not exist on disk.and exits with an error rather than crashing.Made with Cursor