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

Don’t silence errors that occur while reading metadata #3028

Merged
merged 4 commits into from Apr 15, 2018

Conversation

Kwpolska
Copy link
Member

I tried to create a YAML version of Dr Nikola’s Vendetta while debugging an issue. I had a silent failure (no metadata was read). Poking around with pdb revealed a syntax error (apostrophes clashing).

Turns out there was a try-except whose clause was too broad. New output is much more useful:

Scanning posts.....[2018-04-14T17:37:13Z] ERROR: scan_posts: Error reading post pages/dr-nikolas-vendetta.rst
[2018-04-14T17:37:13Z] ERROR: Nikola: Error reading timeline
[2018-04-14T17:37:13Z] ERROR: Nikola: Error loading tasks. An unhandled exception occurred.
Traceback (most recent call last):
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/doit_cmd.py", line 172, in run
    return command.parse_execute(args)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/cmd_base.py", line 127, in parse_execute
    return self.execute(params, args)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/cmd_base.py", line 389, in execute
    self, params, args)
  File "/Users/kwpolska/git/nikola/nikola/__main__.py", line 277, in load_tasks
    self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/loader.py", line 313, in generate_tasks
    for task_dict, x_doc in flat_generator(gen_result, gen_doc):
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/loader.py", line 26, in flat_generator
    for item in gen:
  File "/Users/kwpolska/git/nikola/nikola/nikola.py", line 1902, in gen_tasks
    for task in flatten(pluginInfo.plugin_object.gen_tasks()):
  File "/Users/kwpolska/git/nikola/nikola/nikola.py", line 1896, in flatten
    for t in task:
  File "/Users/kwpolska/git/nikola/nikola/plugins/task/tagcloud.py", line 43, in gen_tasks
    self.site.scan_posts()
  File "/Users/kwpolska/git/nikola/nikola/nikola.py", line 2021, in scan_posts
    timeline = p.plugin_object.scan()
  File "/Users/kwpolska/git/nikola/nikola/plugins/misc/scan_posts.py", line 101, in scan
    metadata_extractors_by=self.site.metadata_extractors_by
  File "/Users/kwpolska/git/nikola/nikola/post.py", line 164, in __init__
    default_metadata, default_used_extractor = get_meta(self, lang=None)
  File "/Users/kwpolska/git/nikola/nikola/post.py", line 1032, in get_meta
    new_meta, used_extractor = get_metadata_from_file(post.source_path, post, config, lang, metadata_extractors_by)
  File "/Users/kwpolska/git/nikola/nikola/post.py", line 971, in get_metadata_from_file
    new_meta = extractor.extract_text(source_text)
  File "/Users/kwpolska/git/nikola/nikola/plugin_categories.py", line 435, in extract_text
    meta = self._extract_metadata_from_text(split[0])
  File "/Users/kwpolska/git/nikola/nikola/metadata_extractors.py", line 196, in _extract_metadata_from_text
    meta = yaml.safe_load(source_text[4:])
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/__init__.py", line 94, in safe_load
    return load(stream, SafeLoader)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/constructor.py", line 35, in get_single_data
    node = self.get_single_node()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/parser.py", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1:
    title: 'A BID FOR FORTUNE OR; DR ...
    ^
expected <block end>, but found '<scalar>'
  in "<unicode string>", line 1, column 42:
     ...  BID FOR FORTUNE OR; DR. NIKOLA'S VENDETTA'
                                         ^

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

LGTM. Also: if there is an important corner case we forgot (I don't think there should be), we'll probably notice soon when trying to build our blogs with the new master after this has been merged.

@Kwpolska
Copy link
Member Author

It’s probably not a corner case, more of a silenced error that should have been reported. (The errors in tests were caused by mocking, not real code.)

@Kwpolska Kwpolska merged commit 0e8c7a6 into master Apr 15, 2018
@Kwpolska
Copy link
Member Author

Also, thanks for reviewing!

@Kwpolska Kwpolska deleted the fix-metadata-error-reporting branch April 15, 2018 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants