Preserve real parse diagnostics instead of the generic section wrapper - #18
Merged
Conversation
Fixes #12. The two generic section loops caught every exception and replaced it with "Error reading section %r", so a precise ParseError raised deep in a reader ("Unterminated string") was invisible to anyone showing str(e), and genuine internal bugs were laundered into what looked like a file-format complaint. - Both section loops now re-raise ParseError untouched, and include repr() of any other exception when wrapping it, so an internal error is still identifiable as one. - load_smaug_vnum_section / load_swr_vnum_section sliced instead of indexed when peeking at the character after '#', so a file ending in '#' ends the section instead of raising IndexError. - CircleAreaFile.read_record_header raises a located ParseError on a non-numeric record header instead of letting int() raise a bare ValueError. test_error_reporting.py covers all four behaviours; all six tests fail on the previous code. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PQh6Vypbkqk4vnqPUE8yTY
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 #12.
The problem
Both generic section loops caught everything and replaced it with one message:
That discarded the precise
ParseErroran inner reader had already raised, and itlaundered real internal bugs into what looked like a file-format complaint.
The fix
AreaFile.load_sections, the Smaug/SWR loop) re-raiseParseErroruntouched, and includerepr(error)when wrapping anything else, so aninternal error is still identifiable as one.
load_smaug_vnum_section/load_swr_vnum_sectionslice instead of index whenpeeking at the character after
#(self.data[self.index + 1:self.index + 2]), so afile ending in
#ends the section rather than raisingIndexError.CircleAreaFile.read_record_headerraises a locatedParseErroron a non-numericrecord header instead of letting
int()escape a bareValueError.No new abstraction; three small edits plus a test file.
Verification
test_error_reporting.py(6 tests) covers all four behaviours. With the source changestashed, all six fail:
With the fix:
6 passed in 0.77s. Full suite:950 passed in 94.76s.End-to-end, exercising what a CLI would actually print via
str(e):ruff checkonarea_reader/__init__.pyreports the same 153 pre-existing errors beforeand after; the new test file is clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PQh6Vypbkqk4vnqPUE8yTY