-
Notifications
You must be signed in to change notification settings - Fork 0
fix: improve error messages for unclosed code fences (issue #31) #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When a code fence is left unclosed earlier in a document, docuchango's
error messages were confusing and pointed to much later in the file.
Changes:
- Detect when a "closing fence with extra text" is actually an opening
fence being misinterpreted due to an unclosed block earlier
- Report the unclosed block at its actual location first
- Add explanatory message about cascading errors
- Avoid confusing messages about "extra text" when it's a language specifier
Before:
Line 35: Closing code fence has extra text (```text), should be just ```
Line 38: Opening code fence missing language (use ```text for plain text)
Unclosed code block starting at line 38 (```<none>)
After:
Unclosed code block starting at line 21 (```markdown)
Line 35: This appears to be a new opening fence (```text), but was
interpreted as a closing fence due to the unclosed block above
The fix uses a heuristic: if a "closing fence" has what looks like a
language specifier (single word, <= 20 chars), it's likely actually an
opening fence being misinterpreted.
Adds comprehensive test coverage for this scenario.
Fixes #31
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
==========================================
+ Coverage 61.01% 61.58% +0.57%
==========================================
Files 18 23 +5
Lines 2193 2939 +746
Branches 378 545 +167
==========================================
+ Hits 1338 1810 +472
- Misses 812 1065 +253
- Partials 43 64 +21
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes confusing error messages when markdown code fences are left unclosed. Previously, unclosed fences caused cascading errors that pointed to wrong locations and suggested unrelated problems. The fix detects when a "closing fence with extra text" is actually an opening fence being misinterpreted, reports the root cause at the correct line, and explains the cascading effect.
Key Changes:
- Enhanced code fence validation logic to detect unclosed blocks earlier
- Improved error messaging to point to the actual unclosed fence location
- Added recovery mechanism to continue validation after detecting misinterpreted fences
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docuchango/validator.py | Added heuristic detection for misinterpreted opening fences and improved error reporting for unclosed code blocks |
| tests/test_validator.py | Added comprehensive test case verifying correct detection and error messages for unclosed code fence scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use `' ' not in remainder` instead of `not ' ' in remainder` for better readability and Python best practices - Extract magic number 18 as UNCLOSED_BLOCK_START_LINE constant with explanatory comment in test Co-Authored-By: Copilot <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
✅ Addressed both review comments in commit 755da5c:
All tests still passing. Thank you for the feedback! |
Format validator.py and test_validator.py to pass CI lint checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix two lint issues: 1. Remove unnecessary else after continue (RET507) 2. Change UNCLOSED_BLOCK_START_LINE to lowercase (N806) All tests passing. Lint checks passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
Fixes confusing error messages when a code fence is left unclosed earlier in a document.
Problem (Issue #31)
When a code fence is left unclosed earlier in a markdown document, docuchango's error messages pointed to much later in the file and were confusing. The errors suggested that closing fences had "extra text" when they actually had language specifiers, making it difficult to diagnose the real issue.
Example of Confusing Errors (Before)
Given a file with:
markdown` (opening fence)text` (new opening fence)(closing fence)Old error output:
New error output:
Solution
The fix detects when a "closing fence with extra text" is actually an opening fence being misinterpreted:
Changes
docuchango/validator.py: Enhanced code fence validation logic (lines 872-900)tests/test_validator.py: Added comprehensive test for issue Confusing error messages when code fence is unclosed earlier in document #31 scenarioTest Coverage
New test
test_unclosed_code_fence_error_messageverifies:Test Status
✅ All 629 tests passing, 1 skipped
Closes #31
🤖 Generated with Claude Code