mdmintz / pdbp

pdbp (Pdb+): A drop-in replacement for pdb and pdbpp. To replace "pdb", add "import pdbp" to an "__init__.py" file.
Other
75 stars 2 forks source link

Screen clearing hides exceptions #58

Closed bwoodsend closed 11 months ago

bwoodsend commented 11 months ago

Whenever an exception is raised, the usual exception+stack trace is printed but then pdbp runs its clear screen leaving you with nothing but what comes after – an arrow pointing to the offending line of code without even the exception type to say what's wrong with it.

For example:

echo 'assert 0' > test.py
python -m pdbp test.py

If I c through to the exception I just get the following which is pretty but less useful to me than boring old pdb.

[4] > /tmp/test.py(1)

   1  -> assert 0
(Pdb+) 

It would be a lot more practical for the sequence to be, clear screen -> dump exception/stacktrace -> print current code location.

That all said, I'm personally happier to let the terminal do the scrolling. If I disable the clear screen (edit pdbp.py and set CLEARSCREEN to an empty string), the resultant UX is perfect for me.

mdmintz commented 11 months ago

The behavior that you're seeing is sticky mode, which is the default mode. Type sticky from a Pdb+ prompt and press Enter to switch to non-sticky mode, which gets you what you want.

You can also update CLEARSCREEN behavior directly from a breakpoint:

(Pdb+) from seleniumbase import pdbp
(Pdb+) pdbp.CLEARSCREEN = ""
bwoodsend commented 11 months ago

With sticky mode off, I loose the nice function context. Why do seeing the function and seeing the exception have to be mutually exclusive? Why not have both?

mdmintz commented 11 months ago

You can still scroll up to see the exception message if there is one. And sometimes, there's a long exception message, in which case you wouldn't want it to cover over the location in the current stack (or at least most people wouldn't want that.)

And if you don't like the default settings, you can easily modify them by updating an __init__.py file with those settings. Eg:

from seleniumbase import pdbp
pdbp.CLEARSCREEN = ""
import pdb
if hasattr(pdb, "DefaultConfig"):
    pdb.DefaultConfig.filename_color = pdb.Color.fuchsia
    pdb.DefaultConfig.line_number_color = pdb.Color.turquoise
    pdb.DefaultConfig.truncate_long_lines = False
    pdb.DefaultConfig.sticky_by_default = True
max-sixty commented 6 months ago

FWIW I do find this behavior quite confusing. While it's easy to handle once you know about it, it makes it harder to encourage colleagues to move from pdb/pdppp to pdbp given the modal first experience is "where's did the exception go??".

To the extent sticky mode could still show the exception, that would be much nicer!