From: Oleg Broytman Date: Sat, 10 Sep 2016 21:25:07 +0000 (+0300) Subject: lib/python/init.py: catch and report pager errors X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=89b04ad56e3c4b9e3073c250bb525051c6f1405b;p=dotfiles.git lib/python/init.py: catch and report pager errors Most probably it's UnicodeEncodeError. --- diff --git a/lib/python/init.py b/lib/python/init.py index 6a6ff9a..1697a08 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -122,6 +122,8 @@ def init(): # set displayhook and excepthook from pprint import pprint + from traceback import format_exception, print_exc + pager = os.environ.get("PAGER") or 'more' # if your pager is 'less', options '-F' and '-R' must be passed to it, @@ -165,13 +167,15 @@ def init(): if value is not None: builtins._ = value pager = Pager() - pager.pprint(value) + try: + pager.pprint(value) + except: + pager.stdout = ColoredFile(pager.stdout, '\033[31m') # red + print_exc(file=pager) pager.close() sys.displayhook = displayhook - from traceback import format_exception - def excepthook(etype, evalue, etraceback): lines = format_exception(etype, evalue, etraceback) pager = Pager()