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 4 commits into from Apr 15, 2018


Copy link

@Kwpolska Kwpolska commented Apr 14, 2018

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/", line 172, in run
    return command.parse_execute(args)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/", line 127, in parse_execute
    return self.execute(params, args)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/", line 389, in execute
    self, params, args)
  File "/Users/kwpolska/git/nikola/nikola/", 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/", 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/", line 26, in flat_generator
    for item in gen:
  File "/Users/kwpolska/git/nikola/nikola/", line 1902, in gen_tasks
    for task in flatten(pluginInfo.plugin_object.gen_tasks()):
  File "/Users/kwpolska/git/nikola/nikola/", line 1896, in flatten
    for t in task:
  File "/Users/kwpolska/git/nikola/nikola/plugins/task/", line 43, in gen_tasks
  File "/Users/kwpolska/git/nikola/nikola/", line 2021, in scan_posts
    timeline = p.plugin_object.scan()
  File "/Users/kwpolska/git/nikola/nikola/plugins/misc/", line 101, in scan
  File "/Users/kwpolska/git/nikola/nikola/", line 164, in __init__
    default_metadata, default_used_extractor = get_meta(self, lang=None)
  File "/Users/kwpolska/git/nikola/nikola/", 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/", line 971, in get_metadata_from_file
    new_meta = extractor.extract_text(source_text)
  File "/Users/kwpolska/git/nikola/nikola/", line 435, in extract_text
    meta = self._extract_metadata_from_text(split[0])
  File "/Users/kwpolska/git/nikola/nikola/", 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/", line 94, in safe_load
    return load(stream, SafeLoader)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 72, in load
    return loader.get_single_data()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 35, in get_single_data
    node = self.get_single_node()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 36, in get_single_node
    document = self.compose_document()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 98, in check_event
    self.current_event = self.state()
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/yaml/", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" %, 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:

Kwpolska added 3 commits Apr 14, 2018
Signed-off-by: Chris Warrick <>
Signed-off-by: Chris Warrick <>
Signed-off-by: Chris Warrick <>
Copy link

@felixfontein felixfontein left a comment

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.

Copy link
Member Author

@Kwpolska Kwpolska commented Apr 15, 2018

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
5 checks passed
Copy link
Member Author

@Kwpolska Kwpolska commented Apr 15, 2018

Also, thanks for reviewing!

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

Successfully merging this pull request may close these issues.

None yet

2 participants