Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc89a66

Browse files
authoredMay 19, 2017
Merge branch 'master' into flowr-no-jquery
2 parents 31b3d7a + 356a1c4 commit cc89a66

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features
55
--------
66

77
* Ported gallery image layout to base theme (Issue #2775)
8+
* Better error handling when posts can't be parsed (Issue #2771)
89
* Use ``.theme`` files to store theme metadata (Issue #2758)
910
* New ``add_header_permalinks`` filter, for Sphinx-style header links
1011
(Issue #2636)

‎nikola/__main__.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,17 @@ def load_tasks(self, cmd, opt_values, pos_args):
275275
}
276276
DOIT_CONFIG['default_tasks'] = ['render_site', 'post_render']
277277
DOIT_CONFIG.update(self.nikola._doit_config)
278-
tasks = generate_tasks(
279-
'render_site',
280-
self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
281-
latetasks = generate_tasks(
282-
'post_render',
283-
self.nikola.gen_tasks('post_render', "LateTask", 'Group of tasks to be executed after site is rendered.'))
284-
signal('initialized').send(self.nikola)
278+
try:
279+
tasks = generate_tasks(
280+
'render_site',
281+
self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
282+
latetasks = generate_tasks(
283+
'post_render',
284+
self.nikola.gen_tasks('post_render', "LateTask", 'Group of tasks to be executed after site is rendered.'))
285+
signal('initialized').send(self.nikola)
286+
except Exception:
287+
LOGGER.error('Error loading tasks')
288+
sys.exit(3)
285289
return tasks + latetasks, DOIT_CONFIG
286290

287291

@@ -363,7 +367,12 @@ def run(self, cmd_args):
363367
LOGGER.error("This command needs to run inside an "
364368
"existing Nikola site.")
365369
return 3
366-
return super(DoitNikola, self).run(cmd_args)
370+
try:
371+
return super(DoitNikola, self).run(cmd_args)
372+
except Exception:
373+
if self.nikola.debug:
374+
raise
375+
return 1
367376

368377
@staticmethod
369378
def print_version():

‎nikola/nikola.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,11 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
21252125
self.pages = []
21262126

21272127
for p in sorted(self.plugin_manager.getPluginsOfCategory('PostScanner'), key=operator.attrgetter('name')):
2128-
timeline = p.plugin_object.scan()
2128+
try:
2129+
timeline = p.plugin_object.scan()
2130+
except Exception:
2131+
utils.LOGGER.error('Error reading timeline')
2132+
raise
21292133
# FIXME: can there be conflicts here?
21302134
self.timeline.extend(timeline)
21312135

‎nikola/post.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ def __init__(
198198
try:
199199
self.date = to_datetime(self.meta[self.default_lang]['date'], tzinfo)
200200
except ValueError:
201-
raise ValueError("Invalid date '{0}' in file {1}".format(self.meta[self.default_lang]['date'], source_path))
201+
if not self.meta[self.default_lang]['date']:
202+
msg = 'Missing date in file {}'.format(source_path)
203+
else:
204+
msg = "Invalid date '{0}' in file {1}".format(self.meta[self.default_lang]['date'], source_path)
205+
LOGGER.error(msg)
206+
raise ValueError(msg)
202207

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

0 commit comments

Comments
 (0)
Please sign in to comment.