Skip to content

Commit

Permalink
Show last exception text and NIKOLA_DEBUG explanation (#2774 #2771)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 21, 2017
1 parent a54a3e1 commit cc27a4a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nikola/__main__.py
Expand Up @@ -284,9 +284,10 @@ def load_tasks(self, cmd, opt_values, pos_args):
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')
LOGGER.error('Error loading tasks. An unhandled exception occurred.')
if self.nikola.debug:
raise
_print_exception()
sys.exit(3)
return tasks + latetasks, DOIT_CONFIG

Expand Down Expand Up @@ -372,8 +373,10 @@ def run(self, cmd_args):
try:
return super(DoitNikola, self).run(cmd_args)
except Exception:
LOGGER.error('An unhandled exception occurred.')
if self.nikola.debug:
raise
_print_exception()
return 1

@staticmethod
Expand Down Expand Up @@ -410,5 +413,12 @@ def levenshtein(s1, s2):
return previous_row[-1]


def _print_exception():
"""Print an exception in a more friendly, shorter style."""
etype, evalue, _ = sys.exc_info()
LOGGER.error(''.join(traceback.format_exception(etype, evalue, None, limit=0, chain=False)).strip())
LOGGER.notice("To see more details, run Nikola in debug mode (set environment variable NIKOLA_DEBUG=1)")


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

0 comments on commit cc27a4a

Please sign in to comment.