Skip to content

Commit

Permalink
Merge pull request #2858 from getnikola/env-show-tracebacks
Browse files Browse the repository at this point in the history
Add NIKOLA_SHOW_TRACEBACKS environment variable
  • Loading branch information
Kwpolska committed Jul 3, 2017
2 parents 208dfac + 1779cb7 commit fe76832
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Add ``NIKOLA_SHOW_TRACEBACKS`` environment variable that shows
full tracebacks instead of one-line summaries
* Use ``PRETTY_URLS`` by default on all sites (Issue #1838)
* Feed link generation is completely refactored (Issue #2844)
* Added ``extract_metadata`` and ``split_metadata`` to the
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.txt
Expand Up @@ -2862,7 +2862,8 @@ stderr. Thus, you must use the different call. (Alternatively, you could run
with ``nikola build -v 2``, which disables the redirections.)

To show more logging messages, as well as full tracebacks, you need to set an
environment variable: ``NIKOLA_DEBUG=1``
environment variable: ``NIKOLA_DEBUG=1``. If you want to only see tracebacks,
set ``NIKOLA_SHOW_TRACEBACKS=1``.

Shell Tab Completion
~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions nikola/__init__.py
Expand Up @@ -31,6 +31,7 @@

__version__ = '8.0.0.dev0'
DEBUG = bool(os.getenv('NIKOLA_DEBUG'))
SHOW_TRACEBACKS = bool(os.getenv('NIKOLA_SHOW_TRACEBACKS'))

if sys.version_info[0] == 2:
raise Exception("Nikola does not support Python 2.")
Expand Down
6 changes: 3 additions & 3 deletions nikola/__main__.py
Expand Up @@ -280,7 +280,7 @@ def load_tasks(self, cmd, opt_values, pos_args):
signal('initialized').send(self.nikola)
except Exception:
LOGGER.error('Error loading tasks. An unhandled exception occurred.')
if self.nikola.debug:
if self.nikola.debug or self.nikola.show_tracebacks:
raise
_print_exception()
sys.exit(3)
Expand Down Expand Up @@ -369,7 +369,7 @@ def run(self, cmd_args):
return super(DoitNikola, self).run(cmd_args)
except Exception:
LOGGER.error('An unhandled exception occurred.')
if self.nikola.debug:
if self.nikola.debug or self.nikola.show_tracebacks:
raise
_print_exception()
return 1
Expand Down Expand Up @@ -412,7 +412,7 @@ def _print_exception():
"""Print an exception in a friendlier, 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)")
LOGGER.notice("To see more details, run Nikola in debug mode (set environment variable NIKOLA_DEBUG=1) or use NIKOLA_SHOW_TRACEBACKS=1")


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion nikola/nikola.py
Expand Up @@ -60,7 +60,7 @@

from .post import Post # NOQA
from .state import Persistor
from . import DEBUG, filters, utils, hierarchy_utils, shortcodes
from . import DEBUG, SHOW_TRACEBACKS, filters, utils, hierarchy_utils, shortcodes
from .plugin_categories import (
Command,
LateTask,
Expand Down Expand Up @@ -413,6 +413,7 @@ def __init__(self, **config):
self._MESSAGES = None
self.filters = {}
self.debug = DEBUG
self.show_tracebacks = SHOW_TRACEBACKS
self.colorful = config.pop('__colorful__', False)
self.invariant = config.pop('__invariant__', False)
self.quiet = config.pop('__quiet__', False)
Expand Down

0 comments on commit fe76832

Please sign in to comment.