@@ -210,11 +210,20 @@ async def update_frontmatter(path: FilePath, updates: Dict[str, Any]) -> str:
210210 # Read current content
211211 content = path_obj .read_text (encoding = "utf-8" )
212212
213- # Parse current frontmatter
213+ # Parse current frontmatter with proper error handling for malformed YAML
214214 current_fm = {}
215215 if has_frontmatter (content ):
216- current_fm = parse_frontmatter (content )
217- content = remove_frontmatter (content )
216+ try :
217+ current_fm = parse_frontmatter (content )
218+ content = remove_frontmatter (content )
219+ except (ParseError , yaml .YAMLError ) as e :
220+ # Log warning and treat as plain markdown without frontmatter
221+ logger .warning (
222+ f"Failed to parse YAML frontmatter in { path_obj } : { e } . "
223+ "Treating file as plain markdown without frontmatter."
224+ )
225+ # Keep full content, treat as having no frontmatter
226+ current_fm = {}
218227
219228 # Update frontmatter
220229 new_fm = {** current_fm , ** updates }
@@ -229,11 +238,13 @@ async def update_frontmatter(path: FilePath, updates: Dict[str, Any]) -> str:
229238 return await compute_checksum (final_content )
230239
231240 except Exception as e : # pragma: no cover
232- logger .error (
233- "Failed to update frontmatter" ,
234- path = str (path ) if isinstance (path , (str , Path )) else "<unknown>" ,
235- error = str (e ),
236- )
241+ # Only log real errors (not YAML parsing, which is handled above)
242+ if not isinstance (e , (ParseError , yaml .YAMLError )):
243+ logger .error (
244+ "Failed to update frontmatter" ,
245+ path = str (path ) if isinstance (path , (str , Path )) else "<unknown>" ,
246+ error = str (e ),
247+ )
237248 raise FileError (f"Failed to update frontmatter: { e } " )
238249
239250
0 commit comments