From 89b04ad56e3c4b9e3073c250bb525051c6f1405b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 11 Sep 2016 00:25:07 +0300 Subject: [PATCH] lib/python/init.py: catch and report pager errors Most probably it's UnicodeEncodeError. --- lib/python/init.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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() -- 2.39.5