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

[FIX] graceful error when failing to load invalid yml #2009

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

Remi-Gau
Copy link
Collaborator

@Remi-Gau
Copy link
Collaborator Author

The error at least now mentions in which file the error is.

2024-12-16 11:28:13,235 [    INFO] No schema path specified, defaulting to the bundled schema, `/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/data/schema`.
Traceback (most recent call last):
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/types/namespace.py", line 279, in _read_yaml_dir
    mapping[subpath.stem] = yaml.safe_load(subpath.read_text())
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/__init__.py", line 125, in safe_load
    return load(stream, SafeLoader)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/scanner.py", line 223, in fetch_more_tokens
    return self.fetch_value()
           ^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/yaml/scanner.py", line 577, in fetch_value
    raise ScannerError(None, None,
yaml.scanner.ScannerError: mapping values are not allowed here
  in "<unicode string>", line 8, column 15:
      display_name: Acquisition
                  ^

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

Traceback (most recent call last):
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/types/namespace.py", line 277, in _read_yaml_dir
    mapping[subpath.name] = _read_yaml_dir(subpath)
                            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/types/namespace.py", line 281, in _read_yaml_dir
    raise ValueError(f"There was an error reading the file: {subpath}") from e
ValueError: There was an error reading the file: /home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/data/schema/objects/entities.yaml

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

Traceback (most recent call last):
  File "/home/remi/github/bids/specification/tmp.py", line 2, in <module>
    schema_obj = schema.load_schema()
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/schema.py", line 203, in load_schema
    schema = Namespace.from_directory(schema_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/types/namespace.py", line 261, in from_directory
    return cls.build(_read_yaml_dir(Path(path)))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/types/namespace.py", line 281, in _read_yaml_dir
    raise ValueError(f"There was an error reading the file: {subpath}") from e
ValueError: There was an error reading the file: /home/remi/github/bids/website/env/lib/python3.12/site-packages/bidsschematools/data/schema/objects

@@ -116,6 +116,7 @@ plugins:
- css/watermark.css
- macros:
module_name: tools/mkdocs_macros_bids/main
on_error_fail: true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding this extra check because the wesbite would still build but with broken pages which is not something we want

@effigies effigies added schema-code Updates or changes to the code used to parse, filter, and render the schema. exclude-from-changelog This item will not feature in the automatically generated changelog labels Dec 17, 2024
@effigies effigies merged commit 448b37d into bids-standard:master Dec 17, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude-from-changelog This item will not feature in the automatically generated changelog schema-code Updates or changes to the code used to parse, filter, and render the schema.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ungracefull error when loading schema with yaml syntax error
2 participants