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

Misformed YAML context crashes with unhelpful error #122

Open
pathunstrom opened this issue May 26, 2020 · 1 comment
Open

Misformed YAML context crashes with unhelpful error #122

pathunstrom opened this issue May 26, 2020 · 1 comment

Comments

@pathunstrom
Copy link

pathunstrom commented May 26, 2020

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."

@pathunstrom
Copy link
Author

I'm willing to do the work on this, just want to confirm it's work you think needs done.

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