Skip to content
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

Error while parsing frontmatter having sub items #26

Open
ooker777 opened this issue Apr 29, 2023 · 0 comments
Open

Error while parsing frontmatter having sub items #26

ooker777 opened this issue Apr 29, 2023 · 0 comments

Comments

@ooker777
Copy link

For files having this YAML:

---
a:
  - b
---

It will have this error:

Traceback (most recent call last):
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\metadata.py", line 356, in _parse_1
    fm = frontmatter.loads(note_content)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\frontmatter\__init__.py", line 165, in loads
    metadata, content = parse(text, encoding, handler, **defaults)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\frontmatter\__init__.py", line 82, in parse
    fm = handler.load(fm)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\frontmatter\default_handlers.py", line 238, in load
    return yaml.load(fm, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\yaml\__init__.py", line 81, in load
    return loader.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ganuo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\yaml\constructor.py", line 49, in get_single_data
    node = self.get_single_node()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "yaml\_yaml.pyx", line 673, in yaml._yaml.CParser.get_single_node
  File "yaml\_yaml.pyx", line 687, in yaml._yaml.CParser._compose_document
  File "yaml\_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 845, in yaml._yaml.CParser._compose_mapping_node
  File "yaml\_yaml.pyx", line 694, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 860, in yaml._yaml.CParser._parse_next_event
yaml.scanner.ScannerError: while scanning a simple key
  in "<unicode string>", line 3, column 1
could not find expected ':'
  in "<unicode string>", line 4, column 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\note.py", line 39, in __init__
    self.metadata: NoteMetadata = NoteMetadata(self.content)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\metadata.py", line 698, in __init__
    self.frontmatter = Frontmatter(note_content)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\metadata.py", line 67, in __init__
    self.metadata: MetaDict = self._parse(note_content)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\metadata.py", line 349, in _parse
    return parse_fn(note_content)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\metadata.py", line 358, in _parse_1
    raise InvalidFrontmatterError(exception=e) from e
pyomd.exceptions.InvalidFrontmatterError: Error while parsing frontmatter!. Exception:
while scanning a simple key
  in "<unicode string>", line 3, column 1
could not find expected ':'
  in "<unicode string>", line 4, column 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\QC supplements\Vaults\C Nhóm hỗ trợ người tự học\Obsidian, quản lý dự án và công cụ nghĩ\Thiết lập\test.py", line 14, in <module>
    allnotes = Notes(path_dir)
               ^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\note.py", line 166, in __init__
    self.add(paths=paths, recursive=recursive)
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\note.py", line 193, in add
    self.notes.append(Note(path=pth_f))
                      ^^^^^^^^^^^^^^^^
  File "D:\Programming\Obsidian\py-obsidianmd\pyomd\note.py", line 41, in __init__
    raise ParsingNoteMetadataError(path=path, exception=e) from e
pyomd.exceptions.ParsingNoteMetadataError: Error while parsing metadata for note at path: "D:\QC supplements\Vaults\C Nhóm hỗ trợ người tự học\Obsidian, quản lý dự án và công cụ nghĩ\🌟 BẮT ĐẦU Ở ĐÂY.md". Exception:
Error while parsing frontmatter!. Exception:
while scanning a simple key
  in "<unicode string>", line 3, column 1
could not find expected ':'
  in "<unicode string>", line 4, column 1

Command:

from pathlib import Path
from pyomd import Notes
from pyomd.metadata import MetadataType

path_dir = Path('D:\QC supplements\Vaults\C Nhóm hỗ trợ người tự học\Obsidian, quản lý dự án và công cụ nghĩ')
allnotes = Notes(path_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant