Fix CLI error detail and BOM handling for JSON input - #438
Merged
Merged
Conversation
The file, string, and URL readers replaced the JSONDecodeError with a fixed message, so the CLI could only say the input was invalid. Append the decoder message so users see the line and column. Fixes #436
Files, URL bodies, and strings starting with a BOM were rejected as invalid JSON. Windows tools such as PowerShell and Notepad write the BOM by default, so decode with utf-8-sig and drop a leading U+FEFF from string input. Fixes #437
Contributor
Reviewer's GuideUpdates all JSON readers to accept leading UTF-8 BOMs and preserve decoder error details, including line and column positions, while maintaining existing error prefixes; adds end-to-end coverage and behavioral documentation. Flow diagram for BOM-tolerant JSON input and detailed errorsflowchart LR
File["File input"] --> FileReader[readfromjson]
URL["URL input"] --> URLReader[readfromurl]
String["String or stdin input"] --> StringReader[readfromstring]
FileReader --> Decode["Decode JSON after removing leading BOM"]
URLReader --> Decode
StringReader --> Decode
Decode --> Parsed["Parsed JSON"]
Decode --> Error["Source-specific error with decoder line and column"]
Error --> CLI["CLI displays unchanged error prefix plus details"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #438 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 1032 1032
=========================================
Hits 1032 1032
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
PyPy reports the unterminated object at line 1 for the sample file while CPython reports the missing comma at line 372. The CLI contract is that a position is shown, so match the pattern, not the text. Refs #436
ty 0.0.83 marks Number.__hash__ abstract and enforces dict and list invariance, so the CustomNumber helpers could not be instantiated and nested payload literals were not assignable to JSONValue. Implement __hash__ and declare the payloads as JSONValue. Also make the omit-list test compare the result instead of asserting a literal. Fixes #439
…-details # Conflicts: # tests/test_dict2xml.py
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
Three fixes, one commit each, plus a small test follow-up.
Before:
After:
Error prefixes are unchanged, so existing callers matching on them are unaffected. No library code changed for #439; the CustomNumber test helpers gain
__hash__, the affected payloads are declared asJSONValue, and one test that asserted a bare literal now compares the result.Test plan
make teston CPython: 100% coverage; full suite also passes on PyPy 3.10make lintandmake typecheckclean with ty 0.0.83lat checkpasses;lat.md/tests.mdandlat.md/behavior.mdupdatedSummary by Sourcery
Improve JSON input diagnostics and compatibility by preserving decoder locations and accepting UTF-8 BOMs across all readers.
New Features:
Bug Fixes:
Documentation:
Tests: