Repository navigation
Report malformed metadata JSON at the line it breaks on [patch] - #51
Merged
Merged
Conversation
MetadataFile.Deserialize reported every parse failure at Location.None, so the most common toolkit diagnostic could not be clicked through to the bad line even though the JsonException carries its position. A JsonException with a line number is now reported at that line and column in the metadata file. BytePositionInLine counts UTF-8 bytes, so the position is walked through the line a code point at a time, and it is clamped to the line. Failures without a position (NotSupported, InvalidOperation, Argument, a null document) still report no location. Fixes #28 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q4e8DaJpCfoS8XViLjQzcD
|
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.



Fixes #28
What was wrong
MetadataFile.Deserialize<T>reported every parse failure throughcontext.Report, which always usesLocation.None. AJsonExceptionalready carriesLineNumberandBytePositionInLine, but malformed metadata produced a diagnostic that could not be clicked through to the bad line.Change
JsonExceptionbranch, the diagnostic is now reported withReportAtat a new privateLocationOf(ex). The location is in the metadata file, using the existingLocationAthelper.LineNumbercounts\nline feeds from zero, as System.Text.Json does, so the line start is found the same way (LineStart). This also holds for CRLF files.BytePositionInLinecounts UTF-8 bytes. The line is walked one code point at a time (CharactersAt,Utf8Bytes): 1 to 3 bytes per BMP character and 4 per surrogate pair. The position is clamped to the line, and a position at the end of a line or file gives a zero-length span.Location.Noneis kept for aJsonExceptionwithout a line number, for theNotSupportedException/InvalidOperationException/ArgumentExceptionbranches, for the null-document case, and when there is noSourceText.Tests (
GeneratorBaseTests)AMalformedMetadataFileIsReportedAtTheBadLine(LF and CRLF):{"things": [1,,2]}spread so the error is on line 3. The location is an external file namedthings.json, withStartLinePosition.Line == 2and the column System.Text.Json reports (the first comma of the pair).AParseFailureAfterMultiByteCharactersIsLocatedByCharacterNotByte:"é😀"before the error lands on the same character as an ASCII twin with the same character layout.AParseFailureAtTheEndOfTheFileIsLocatedAtTheEnd: truncated JSON is located on its last line, within the line.AShapeFailureWithNoPositionIsStillReportedWithoutALocation: an unsupported shape is still reported atLocation.None(a control).With the
MetadataFile.cschange reverted, the 4 location tests fail and the control passes. With it, the full suite passes, 60/60 on net10.0. The local SonarCloud analyzer build (-p:CustomAfterMicrosoftCommonProps=.sonarlint/sonar-local.props) is clean. It flagged cognitive complexity on the first draft, which is why the walk is split into three small helpers.Generated by Claude Code