]> git.phdru.name Git - dotfiles.git/commitdiff
lib/python/init.py: catch and report pager errors
authorOleg Broytman <phd@phdru.name>
Sat, 10 Sep 2016 21:25:07 +0000 (00:25 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 10 Sep 2016 21:26:13 +0000 (00:26 +0300)
Most probably it's UnicodeEncodeError.

lib/python/init.py

index 6a6ff9a8208bda3d0b25858c43d75c2d7c273e33..1697a08d38f364db2e2910a639cfc0ad68765697 100644 (file)
@@ -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()