Skip to content
Permalink
Browse files

Nicer error handling (Fix #2771)

  • Loading branch information
ralsina committed May 18, 2017
1 parent 1d03f5f commit 1f144c39dc6ba0c5330e339e9fa9d80d250c57f5
Showing with 33 additions and 13 deletions.
  1. +1 −0 CHANGES.txt
  2. +17 −8 nikola/__main__.py
  3. +6 −3 nikola/nikola.py
  4. +9 −2 nikola/post.py
@@ -4,6 +4,7 @@ New in master
Features
--------

* Better error handling when posts can't be parsed (Issue #2771)
* New ``add_header_permalinks`` filter, for Sphinx-style header links
(Issue #2636)

@@ -275,13 +275,19 @@ def load_tasks(self, cmd, opt_values, pos_args):
}
DOIT_CONFIG['default_tasks'] = ['render_site', 'post_render']
DOIT_CONFIG.update(self.nikola._doit_config)
tasks = generate_tasks(
'render_site',
self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
latetasks = generate_tasks(
'post_render',
self.nikola.gen_tasks('post_render', "LateTask", 'Group of tasks to be executed after site is rendered.'))
signal('initialized').send(self.nikola)
try:
tasks = generate_tasks(
'render_site',
self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
latetasks = generate_tasks(
'post_render',
self.nikola.gen_tasks('post_render', "LateTask", 'Group of tasks to be executed after site is rendered.'))
signal('initialized').send(self.nikola)
except Exception:
LOGGER.error('Error loading tasks')
if self.nikola.debug:
raise
return {}, {}
return tasks + latetasks, DOIT_CONFIG


@@ -363,7 +369,10 @@ def run(self, cmd_args):
LOGGER.error("This command needs to run inside an "
"existing Nikola site.")
return 3
return super(DoitNikola, self).run(cmd_args)
try:
return super(DoitNikola, self).run(cmd_args)
except Exception:
pass

@staticmethod
def print_version():
@@ -1086,8 +1086,7 @@ def init_plugins(self, commands_only=False, load_all=False):
# Remove blacklisted plugins
if p[-1].name in self.config['DISABLED_PLUGINS']:
bad_candidates.add(p)
utils.LOGGER.debug('Not loading disabled plugin {}', p[-1].name)
# Remove compilers we don't use
utils.LOGGER.debug('Not loading disabled plugin {}', p[-1].name) # Remove compilers we don't use
if p[-1].details.has_option('Nikola', 'PluginCategory') and p[-1].details.get('Nikola', 'PluginCategory') in ('Compiler', 'PageCompiler'):
bad_candidates.add(p)
self.disabled_compilers[p[-1].name] = p
@@ -2125,7 +2124,11 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
self.pages = []

for p in sorted(self.plugin_manager.getPluginsOfCategory('PostScanner'), key=operator.attrgetter('name')):
timeline = p.plugin_object.scan()
try:
timeline = p.plugin_object.scan()
except Exception:
utils.LOGGER.error('Error reading timeline')
raise
# FIXME: can there be conflicts here?
self.timeline.extend(timeline)

@@ -198,7 +198,12 @@ def __init__(
try:
self.date = to_datetime(self.meta[self.default_lang]['date'], tzinfo)
except ValueError:
raise ValueError("Invalid date '{0}' in file {1}".format(self.meta[self.default_lang]['date'], source_path))
if not self.meta[self.default_lang]['date']:
msg = 'Missing date in file {}'.format(source_path)
else:
msg = "Invalid date '{0}' in file {1}".format(self.meta[self.default_lang]['date'], source_path)
LOGGER.error(msg)
raise ValueError(msg)

if 'updated' not in default_metadata:
default_metadata['updated'] = default_metadata.get('date', None)
@@ -976,7 +981,9 @@ def get_metadata_from_file(source_path, config=None, lang=None):
meta_data = [x.strip() for x in meta_file.readlines()]
return _get_metadata_from_file(meta_data)
except (UnicodeDecodeError, UnicodeEncodeError):
raise ValueError('Error reading {0}: Nikola only supports UTF-8 files'.format(source_path))
msg = 'Error reading {0}: Nikola only supports UTF-8 files'.format(source_path)
LOGGER.error(msg)
raise ValueError(msg)
except Exception: # The file may not exist, for multilingual sites
return {}

0 comments on commit 1f144c3

Please sign in to comment.
You can’t perform that action at this time.