Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Misformed YAML context crashes with unhelpful error #122

Description

@pathunstrom

I forgot the key in a view's dynamic context. The resulting errors:

2020-05-26 08:35:14,078 statik.project  ERROR   Error: Failed to build project. Run Statik in verbose mode (-v) to see additional traceback inform
ation about this error. (in file personal-site\views\blog.yml"). Additional error detail: 'str' object has no attr
ibute 'items'

Verbose mode:

2020-05-26 08:37:31,096 statik.project  DEBUG   Traceback (most recent call last):
  File "personal-site\.venv\lib\site-packages\statik\project.py", line 121, in generate
    self.views = self.load_views()
  File "personal-site\.venv\lib\site-packages\statik\project.py", line 209, in load_views
    views[view_name] = StatikView(
  File "personal-site\.venv\lib\site-packages\statik\views.py", line 340, in __init__
    self.context = StatikContext(
  File "personal-site\.venv\lib\site-packages\statik\context.py", line 29, in __init__
    self.dynamic = underscore_var_names(
  File "personal-site\.venv\lib\site-packages\statik\utils.py", line 120, in underscore_var_names
    for k, v in d.items():
AttributeError: 'str' object has no attribute 'items'

2020-05-26 08:37:31,096 statik.project  ERROR   Error: Failed to build project. Run Statik in verbose mode (-v) to see additional traceback inform
ation about this error. (in file "C:\Users\pathu\src\pathunstrom\personal-site\views\blog.yml"). Additional error detail: 'str' object has no attr
ibute 'items'

Looking at the code, StatikContext knows it's looking for dynamic context as a dict, so wrapping the call to underscore_var_names in a try: except AttributeError should make it possible to give the user a clear explanation of where and what was wrong.

This is only the case if your context is a single item and you forgot the key. If you have multiple items and forget one key, the yaml scanner yells at you about the misformed YAML.

I'd be looking for a message along the lines of "{dynamic|static} context for {file_name} must be a mapping."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions