Skip to content

[BUG] RecursionError when attempting to capture a traceback from an error (Rich v14.0.0) #3682

Closed
@jjallaire

Description

@jjallaire

Describe the bug

After updating to Rich v14.0.0 I get a RecursionError when attempting to capture a traceback from an error.

Here's my function along with the helper function to create the traceback:

def eval_error(
    exception: BaseException,
    exc_type: Type[Any],
    exc_value: BaseException,
    exc_traceback: TracebackType | None,
) -> EvalError:
    # create ansi traceback
    with open(os.devnull, "w") as f:
        console = Console(record=True, file=f, legacy_windows=True)
        console.print(rich_traceback(exc_type, exc_value, exc_traceback))
        traceback_ansi = console.export_text(styles=True)
   
    # return error
    return EvalError(
        message=exception_message(exception),
        traceback=traceback_text,
        traceback_ansi=traceback_ansi,
    )

def rich_traceback(
    exc_type: Type[Any], exc_value: BaseException, exc_traceback: TracebackType | None
) -> RenderableType:
    rich_tb = Traceback.from_exception(
        exc_type=exc_type,
        exc_value=exc_value,
        traceback=exc_traceback,
        suppress=[click, asyncio, tenacity, sys.modules[PKG_NAME]],
        show_locals=False,
        width=CONSOLE_DISPLAY_WIDTH,
    )
    return rich_tb

Here's the stack trace for the RecursionError:

      | 
      | Traceback (most recent call last):
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/src/inspect_ai/_eval/run.py", line 280, in run_task
      |     result = await task_run(tasks[index])
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/src/inspect_ai/_eval/task/run.py", line 389, in task_run
      |     error = eval_error(ex, type, value, traceback)
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/src/inspect_ai/log/_log.py", line 649, in eval_error
      |     console.print(rich_traceback(exc_type, exc_value, exc_traceback))
      |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/src/inspect_ai/log/_log.py", line 665, in rich_traceback
      |     rich_tb = Traceback.from_exception(
      |               ^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/.venv/lib/python3.12/site-packages/rich/traceback.py", line 381, in from_exception
      |     rich_traceback = cls.extract(
      |                      ^^^^^^^^^^^^
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/.venv/lib/python3.12/site-packages/rich/traceback.py", line 466, in extract
      |     Traceback.extract(
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/.venv/lib/python3.12/site-packages/rich/traceback.py", line 466, in extract
      |     Traceback.extract(
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/.venv/lib/python3.12/site-packages/rich/traceback.py", line 466, in extract
      |     Traceback.extract(
      |   [Previous line repeated 2950 more times]
      |   File "/home/parallels/UKGovernmentBEIS/inspect_ai/.venv/lib/python3.12/site-packages/rich/traceback.py", line 491, in extract
      |     iter_locals: Iterable[Tuple[str, object]],
      |                  ~~~~~~~~^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/lib/python3.12/typing.py", line 395, in inner
      |     return _caches[func](*args, **kwds)
      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      | RecursionError: maximum recursion depth exceeded

Platform

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

Running on Linux, running in the VS Code integrated terminal

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich
╭─────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface.                                              │
│                                                                              │
│ ╭──────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 ColorSystem.TRUECOLOR>                                 │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│     color_system = 'truecolor'                                               │
│         encoding = 'utf-8'                                                   │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w'               │
│                    encoding='utf-8'>                                         │
│           height = 20                                                        │
│    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=80, height=20),          │
│                        legacy_windows=False,                                 │
│                        min_width=1,                                          │
│                        max_width=80,                                         │
│                        is_terminal=True,                                     │
│                        encoding='utf-8',                                     │
│                        max_height=20,                                        │
│                        justify=None,                                         │
│                        overflow=None,                                        │
│                        no_wrap=False,                                        │
│                        highlight=None,                                       │
│                        markup=None,                                          │
│                        height=None                                           │
│                    )                                                         │
│            quiet = False                                                     │
│           record = False                                                     │
│         safe_box = True                                                      │
│             size = ConsoleDimensions(width=80, height=20)                    │
│        soft_wrap = False                                                     │
│           stderr = False                                                     │
│            style = None                                                      │
│         tab_size = 8                                                         │
│            width = 80                                                        │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'CLICOLOR': None,              │
│     'COLORTERM': 'truecolor',      │
│     'COLUMNS': None,               │
│     'JPY_PARENT_PID': None,        │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'LINES': None,                 │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'vscode',      │
│     'TERM': 'xterm-256color',      │
│     'TTY_COMPATIBLE': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"
rich==14.0.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions