mfarragher / obsidiantools

Obsidian tools - a Python package for analysing an Obsidian.md vault
Other
402 stars 28 forks source link

Frontmatter parsing error handling not robust #10

Closed deklanw closed 2 years ago

deklanw commented 2 years ago

Frontmatter parsing can throw different exceptions than yaml.scanner.ScannerError. For example, I was testing this library on random Obsidian vaults I found on Github. It throws a ConstructorError on this file https://github.com/valentine195/Obsidian-Vault/blob/89abc098287aa7df0b2735cb229d15897d28c40d/7.%20Assets/Templates/group.md?plain=1#L1-L6 because it tries to parse {{groupTag}} as a YAML mapping. (It seems to be intended as some template for an Obsidian plugin?)

Anyway, since you're just eating the exception it's probably better to just catch any exception.

mfarragher commented 2 years ago

Hi, thanks for raising this. I hope to have a proper look this month once I have more time away from my studies!

mfarragher commented 2 years ago

I've added functionality to parse the curly brackets in a similar example, by escaping those characters: https://github.com/mfarragher/obsidiantools/commit/08a33ba2c5cbf0775a1b8db9363b38bab6126243

Couldn't find an elegant way to remove the \\ from the strings that appear in the front matter (to handle dicts with mixed types), but it at least has the content parsed.