fix: Handle YAML parsing errors gracefully in update_frontmatter (#378)#379
fix: Handle YAML parsing errors gracefully in update_frontmatter (#378)#379phernandez merged 1 commit intomainfrom
Conversation
The update_frontmatter() function was logging ERROR (level 17) for malformed YAML frontmatter instead of handling it gracefully. This caused 1,112+ errors per 3 hours in production from files with titles like "KB: Something" where the colon breaks YAML parsing. This fix applies the same error handling pattern from PR #368's entity_parser.py: - Catch ParseError and yaml.YAMLError when parsing frontmatter - Log as WARNING (level 13) instead of ERROR - Treat file as having no frontmatter and proceed with update - Only log ERROR for actual file operation failures Files with malformed frontmatter now get updated successfully with valid frontmatter instead of spamming error logs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task —— View job PR Review: Fix YAML Error Handling in
|
Summary
Fixes #378 -
update_frontmatter()now handles malformed YAML frontmatter gracefully instead of logging errors.Problem
The
update_frontmatter()function was logging ERROR (level 17) for malformed YAML frontmatter, even though the system should handle these gracefully. This caused 1,112+ errors per 3 hours in production from files with titles likeKB: Somethingwhere the second colon breaks YAML parsing.PR #368 fixed this issue in the entity parser (reading), but
update_frontmatter()(writing) has a separate code path that wasn't updated.Solution
Applied the same error handling pattern from PR #368's
entity_parser.py:ParseErrorandyaml.YAMLErrorwhen parsing frontmatterChanges
src/basic_memory/file_utils.py:213-248: Added graceful YAML error handlingtests/utils/test_file_utils.py:262-290: Added test for malformed YAML handlingTest Coverage
New test
test_update_frontmatter_handles_malformed_yamlverifies:title: KB: Something) are handled gracefullyExpected Impact
Related
🤖 Generated with Claude Code