Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tracebacks don't expand to fit height properly #2042

Closed
henryiii opened this issue Mar 9, 2022 · 6 comments
Closed

[BUG] Tracebacks don't expand to fit height properly #2042

henryiii opened this issue Mar 9, 2022 · 6 comments

Comments

@henryiii
Copy link
Contributor

henryiii commented Mar 9, 2022

Describe the bug

If you put a Traceback inside a container with a height, it exactly chops off the message at the bottom (regardless of how many lines it has, tested with 1 and a longer message producing 2), and instead matches the frame around the traceback. This is currently causing an issue when placing a traceback in a panel in textual.

MWE:

import rich.traceback
import rich.panel

try:
    1/0
except Exception:
    rich.print(rich.panel.Panel(rich.traceback.Traceback(), height=20))

The output has chopped off the bottom of the traceback:

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮                                                   │
│ │                                                                                                  │                                                   │
│ │ /Users/henryschreiner/git/scikit-hep/uproot-browser/tmp2.py:5 in <module>                        │                                                   │
│ │                                                                                                  │                                                   │
│ │   2 import rich.panel                                                                            │                                                   │
│ │   3                                                                                              │                                                   │
│ │   4 try:                                                                                         │                                                   │
│ │ ❱ 5 │   1/0                                                                                      │                                                   │
│ │   6 except Exception:                                                                            │                                                   │
│ │   7 │   rich.print(rich.panel.Panel(rich.traceback.Traceback(), height=20))                      │                                                   │
│ │   8                                                                                              │                                                   │
│ │                                                                                                  │                                                   │
│ │                                                                                                  │                                                   │
│ │                                                                                                  │                                                   │
│ │                                                                                                  │                                                   │
│ │                                                                                                  │                                                   │
│ │                                                                                                  │                                                   │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯                                                   │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

If you do not set the height externally (remove height=20 above), then the correct height is computed:

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮                                                   │
│ │                                                                                                  │                                                   │
│ │ /Users/henryschreiner/git/scikit-hep/uproot-browser/tmp2.py:5 in <module>                        │                                                   │
│ │                                                                                                  │                                                   │
│ │   2 import rich.panel                                                                            │                                                   │
│ │   3                                                                                              │                                                   │
│ │   4 try:                                                                                         │                                                   │
│ │ ❱ 5 │   1/0                                                                                      │                                                   │
│ │   6 except Exception:                                                                            │                                                   │
│ │   7 │   rich.print(rich.panel.Panel(rich.traceback.Traceback())) # , height=20))                 │                                                   │
│ │   8                                                                                              │                                                   │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯                                                   │
│ ZeroDivisionError: division by zero                                                                                                                    │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Platform

Click to expand for output

macOS iterm2.

╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=154 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 45                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=154, height=45),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=154,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=45,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=154, height=45)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 154                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-256color',      │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'iTerm.app',   │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Darwin"
rich==11.2.0
@willmcgugan
Copy link
Collaborator

The issue is that height is being passed to the panel within the traceback. There are a few issue like this to be resolved, since prior to Textual Rich didn't have any concept of height.

@willmcgugan
Copy link
Collaborator

Could you try with version 12.0.0a2

pip install rich==12.0.0a2

@henryiii
Copy link
Contributor Author

That's much better (using 12.0.0, though incompatible with textual ATM). It chops off the bottom if the surrounding container is shorter than the traceback, but I think that's the correct / expected behavior, and much better than the "scale inside frame" to fit. :)

@henryiii
Copy link
Contributor Author

Thanks for the fast fix!

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

@willmcgugan
Copy link
Collaborator

Textual v0.1.17 bumps the Rich dependancy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants