vaaaaanquish / xontrib-readable-traceback

xonsh readable traceback
MIT License
11 stars 3 forks source link

Crashes out of xonsh if exc_info is passed #7

Closed bestlem closed 2 years ago

bestlem commented 2 years ago

In xonsh.tools the signature of print_exception has been changed, adding a exc_info keyword.

Some error routes will use this extra parameter and this kills xonsh.

I can't reproduce with xonsh --no-rc but with my set up just type an unknown environment variable e.g. example with python 3.11 but 3.9 and 3.10 do the same.

§ $AAAAAAA
Traceback (most recent call last):
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/base_shell.py", line 391, in default
    raise exc_info[1]
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/codecache.py", line 63, in run_compiled_code
    func(code, glb, loc)
  File "<stdin>", line 1, in <module>
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/environ.py", line 2103, in __getitem__
    raise KeyError(e.format(key))
KeyError: 'Unknown environment variable: $AAAAAAA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/main.py", line 468, in main
    sys.exit(main_xonsh(args))
             ^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/main.py", line 512, in main_xonsh
    shell.shell.cmdloop()
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/ptk_shell/shell.py", line 407, in cmdloop
    self.default(line, raw_line)
  File "/Users/mark/Library/Python/3.11/lib/python/site-packages/xonsh/base_shell.py", line 402, in default
    print_exception(exc_info=exc_info)
TypeError: _print_exception() got an unexpected keyword argument 'exc_info'
Xonsh encountered an issue during launch
Failback to /bin/zsh
bestlem commented 2 years ago

I don't understand how to set up a xontrib copy and get that to load. As this code is just one file I copied it to my startup files and altered. and made these alterations

@@ -44,7 +44,7 @@
 backtrace._flush=__flush

-def _print_exception(msg=None,  exc_info=None):
+def _print_exception(msg=None):
     """
     Override xonsh.tools.print_exception.
     """
@@ -63,12 +63,8 @@
         with open(log_file, 'a') as f:
             traceback.print_exc(file=f)

-    # is no exec_info() triple is given, use the exception beeing handled at the moment
-    if exc_info is None:
-        exc_info = sys.exc_info()
-
     #backtrace_hock
-    tpe, v, tb = exc_info
+    tpe, v, tb = sys.exc_info()
     if $XONSH_READABLE_TRACEBACK:
         backtrace.hook(
             tb=tb,
vaaaaanquish commented 2 years ago

I was having trouble running into the exact same error. I will take a look.

vaaaaanquish commented 2 years ago

@bestlem Thx. fixed. Please update 0.4.0 : https://pypi.org/project/xontrib-readable-traceback/0.4.0/