cansarigol/pdbr

Error when using post_mortem

matan-h opened this issue · 13 comments

the code:

import pdbr
import sys
try:
    1/0
except Exception:
    pdbr.post_mortem(sys.exc_info()[2])

raises the error:

Traceback (most recent call last):
  File "D:/Program Data/Pycharm/PycharmProjects/python_tell/ttt.py", line 8, in <module>
    1/0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/Program Data/Pycharm/PycharmProjects/python_tell/ttt.py", line 10, in <module>
    pdbr.post_mortem(sys.exc_info()[2])
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\pdbr\__main__.py", line 22, in post_mortem
    pdbr_cls().post_mortem(t)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\pdbr\utils.py", line 70, in pdbr_cls
    return klass()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\pdbr\_pdbr.py", line 55, in __init__
    super().__init__(**init_kwargs)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\terminal\debugger.py", line 32, in __init__
    self.pt_init(pt_session_options)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\terminal\debugger.py", line 74, in pt_init
    style=self.shell.style,
AttributeError: 'TerminalInteractiveShell' object has no attribute 'style'

Thanks for pointing the issue out @matan-h

the issue still exists

Thanks again and sorry about the issue. Could you share a bit more information with me since I didn't reproduce it? like your python, ipython and pdbr versions.

Python - 3.8.2
Ipython - 7.21.0
pdbr - 0.4.7
OS: windows 10

I reproduce it in pycharm venv

@matan-h Could you check version 0.4.8? I believe I fixed the problem.

this error happens only in pycharm in windows after installing the last ipython, and then run the file from pycharm

@matan-h I have no windows machine and I, therefore, use an emulator for it. I couldn't reproduce it anyway.

Screenshot 2021-03-30 at 09 15 22

I tried with 3 different windows commuters. and all of them raise same error

I checked some projects that are claimed with the same error. simple_prompt might be responsible for this error. In version 0.5.0 I forced its value as False even it is set by either ipython config or cli ($pdbr --simple-prompt )

the error fixed.
but now its raise another one:

Traceback (most recent call last):
  File "D:/Program Data/Pycharm/PycharmProjects/python_tell/pdbr_error.py", line 6, in <module>
    pdbr.post_mortem(sys.exc_info()[2])
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\pdbr\__main__.py", line 30, in post_mortem
    p = RichPdb()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\pdbr\_pdbr.py", line 66, in __init__
    super().__init__(**init_kwargs)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\terminal\debugger.py", line 30, in __init__
    Pdb.__init__(self, *args, **kwargs)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\core\debugger.py", line 237, in __init__
    self.shell = TerminalInteractiveShell.instance()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\traitlets\config\configurable.py", line 537, in instance
    inst = cls(*args, **kwargs)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\terminal\interactiveshell.py", line 526, in __init__
    self.init_prompt_toolkit_cli()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\IPython\terminal\interactiveshell.py", line 318, in init_prompt_toolkit_cli
    self.pt_app = PromptSession(
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 468, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 719, in _create_application
    application: Application[_T] = Application(
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\application\application.py", line 277, in __init__
    self.output = output or session.output
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\application\current.py", line 70, in output
    self._output = create_output()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\output\defaults.py", line 73, in create_output
    return Win32Output(stdout, default_color_depth=color_depth_from_env)
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\output\win32.py", line 107, in __init__
    info = self.get_win32_screen_buffer_info()
  File "D:\Program Data\Pycharm\PycharmProjects\python_tell\venv\lib\site-packages\prompt_toolkit\output\win32.py", line 211, in get_win32_screen_buffer_info
    raise NoConsoleScreenBufferError
prompt_toolkit.output.win32.NoConsoleScreenBufferError: No Windows console found. Are you running cmd.exe?

pdbr support only terminal?

Could you try that suggestion in the below link? I wonder whether or not your error will be fixed.
prompt-toolkit/python-prompt-toolkit#406 (comment)

this works.
note that without ipython installed it works also without your correction.
Thank you