Skip to content

NullReferenceException in navigation when TOC references a missing file #3245

@wandergeek

Description

@wandergeek

Describe the bug

Running docs-builder serve on a docset whose docset.yml toc references a Markdown file that does not exist causes a global unhandled System.NullReferenceException while building navigation lookups, instead of a clear validation error.

Stack trace (abbreviated):

System.NullReferenceException: Object reference not set to an instance of an object.
   at Elastic.Documentation.Navigation.NavigationItemExtensions.BuildNavigationLookupsRecursive(INavigationItem, ConditionalWeakTable`2, Dictionary`2)
   at Elastic.Documentation.Navigation.NavigationItemExtensions.BuildNavigationLookups(INavigationItem, ConditionalWeakTable`2)
   at Elastic.Markdown.IO.DocumentationSet..ctor(BuildContext, ILoggerFactory, ICrossLinkResolver)
   at Documentation.Builder.Http.ReloadableGeneratorState..ctor(ILoggerFactory, IDirectoryInfo, IDirectoryInfo, BuildContext, Boolean)
   at Documentation.Builder.Http.DocumentationWebHost..ctor(ILoggerFactory, String, Int32, ScopedFileSystem, ScopedFileSystem, IConfigurationContext, Boolean)
   at Documentation.Builder.Commands.ServeCommand.<Serve>d__4.MoveNext()

Expected behavior

docs-builder serve (or a normal build) should report a diagnostic that the TOC entry points to a missing file (path + docset.yml location), and exit without an unhandled exception.

Steps to reproduce

Tested with docs-builder 1.7.0 (install script from README).

  1. Create an empty directory and a docs folder inside it.

  2. Add docs/docset.yml:

    icon: magnifyWithPlus
    registry: internal
    toc:
      - file: index.md
  3. Do not create docs/index.md (the TOC must reference a file that is absent).

  4. From the repository root (parent of docs/), run:

    docs-builder serve
  5. Observe the process crash with NullReferenceException as above.

Minimal tree:

repro-root/
  docs/
    docset.yml   # toc -> index.md only

Tooling

  • docs-builder
  • migration tooling
  • I'm not sure

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions