Fix #786: Handle corrupted journal files gracefully by renaming them #846
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 an issue where RedNotebook would crash when encountering corrupted journal files containing null characters or other control characters that are invalid in YAML.
Problem
When RedNotebook encountered a corrupted journal file (e.g., one containing null bytes
\x00), the YAML parser would throw aReaderErrorwith the message "unacceptable character #x0000: control characters are not allowed". The application would catch this exception but then callsys.exit(1), causing RedNotebook to crash completely and preventing users from accessing any of their journal entries.Solution
This PR modifies the file loading logic to handle corrupted files gracefully:
ReaderErrormentions control characters, the file is identified as corrupted rather than just malformed_corruptedsuffix (e.g.,2024-10.txt→2024-10_corrupted.txt)Example
Before this fix:
After this fix:
Changes Made
_load_month_from_disk()instorage.pyto detect and rename corrupted filesload_all_months_from_disk()to return information about corrupted filesjournal.pywith recovery instructionsTesting
This change transforms a catastrophic crash into a graceful degradation with clear recovery guidance, significantly improving the user experience when dealing with data corruption.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.