Skip to content

Metadata parse-failure diagnostic has no location, so malformed JSON can't be clicked through to the bad line #28

Description

@matt-edmondson

What's wrong

MetadataFile.Deserialize<T> (SourceGeneratorToolkit/MetadataFile.cs, the local ParseFailed function) reports the parse failure with context.Report(parseFailed, FileName, ex.Message). DiagnosticCatalog.Report always reports at Location.None (DiagnosticCatalog.cs:103).

For a JsonException, the exception already carries LineNumber and BytePositionInLine. MetadataFile also already has the text and a LocationAt(index, length) helper, which it uses to make its other diagnostics navigable. The toolkit's most common diagnostic is the one that isn't navigable, even though the README advertises navigable diagnostics.

Failure scenario

A things.json containing {"things": [1,,2]} on line 3 produces a MetadataParseFailed diagnostic with no file or line in the IDE error list. The only pointer is the "LineNumber: 2 | BytePositionInLine: …" text buried in the message, and double-clicking goes nowhere.

Suggested fix / acceptance criteria

  • In the JsonException branch, when ex.LineNumber has a value and the text is available, compute an offset from ex.LineNumber and ex.BytePositionInLine and report with ReportAt at that location.
    • BytePositionInLine counts UTF-8 bytes, so convert it to a character offset on non-ASCII lines.
    • Clamp the offset to the line length.
  • Keep Location.None for the NotSupportedException, InvalidOperationException and null-document cases, and for a JsonException without a line number.
  • Test: malformed JSON on line 3 produces a diagnostic whose Location.GetLineSpan() has the metadata file's path and StartLinePosition.Line == 2.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions