ihabunek / toot

toot - Mastodon CLI & TUI
GNU General Public License v3.0
1.12k stars 107 forks source link

Crash when viewing a particular toot from TUI #479

Open rexbinary opened 2 months ago

rexbinary commented 2 months ago
❯ toot env
toot 0.43.0
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
macOS-14.4.1-arm64-arm-64bit

When using toot TUI to view: https://mastodon.cloud/@slashdot/112287426200500203 toot TUI crashes with the output below.

Traceback (most recent call last):
  File "/opt/homebrew/bin/toot", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/toot/cli/__init__.py", line 124, in wrapped
    return f(get_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/toot/cli/tui.py", line 73, in tui
    tui.run()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/toot/tui/app.py", line 164, in run
    self.loop.run()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/main_loop.py", line 337, in run
    self._run()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/main_loop.py", line 439, in _run
    self.event_loop.run()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/asyncio_loop.py", line 235, in run
    raise exc.with_traceback(exc.__traceback__)
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/asyncio_loop.py", line 114, in _entering_idle
    callback()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/main_loop.py", line 650, in entering_idle
    self.draw_screen()
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/event_loop/main_loop.py", line 667, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/frame.py", line 481, in render
    body = self.body.render((maxcol, maxrow - ftrim - htrim), focus and self.focus_part == "body")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/columns.py", line 1026, in render
    w.render(w_size, focus=focus and self.focus_position == i),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/padding.py", line 340, in render
    canv = self._original_widget.render((maxcol,) + size[1:], focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/frame.py", line 481, in render
    body = self.body.render((maxcol, maxrow - ftrim - htrim), focus and self.focus_part == "body")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cac
hed_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/toot/tui/scroll.py", line 366, in render
    ow_canv = ow.render(ow_size, focus)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/toot/tui/scroll.py", line 61, in render
    canv_full = ow.render(ow_size, focus)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/padding.py", line 340, in render
    canv = self._original_widget.render((maxcol,) + size[1:], focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/pile.py", line 873, in render
    canv = w.render(w_size, focus=focus and item_focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/pile.py", line 873, in render
    canv = w.render(w_size, focus=focus and item_focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwidgets/text_embed.py", line 217, in render
    partial_canv, tail = self._uw_embed(
                         ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwidgets/text_embed.py", line 405, in _uw_embed
    canv.pad_trim_left_right(-line_index, 0)
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/canvas.py", line 799, in pad_trim_left_right
    shards = shards_trim_sides(shards, trim_left, cols)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/toot/0.43.0_1/libexec/lib/python3.12/site-packages/urwid/canvas.py", line 1124, in shards_trim_sides
    raise ValueError(cols)
ValueError: -124
danschwarz commented 2 months ago

Can't test yet as I'm away from my PC for a few days.

Does this crash occur when viewing with image support enabled or not? If with image support enabled, try it with image support disabled and see if it recurs.

lace-wing commented 1 month ago

Reproduced on my mac, specs are:

$< toot env
toot 0.43.0
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
macOS-14.5-arm64-arm-64bit

Crash log

Other toot commands work mostly fine. I don't know how to disable image viewing in toot tui, but didn't enable any.

danschwarz commented 1 month ago

What version of urwid are you using? And are you viewing with image support enabled or disabled?

lace-wing commented 1 month ago

I'm using /opt/homebrew/Cellar/toot/0.43.0_3/libexec/lib/python3.12/site-packages/term_image/widget/urwid.py installed by brew. I did see image views but just very blur color blocks.

lace-wing commented 4 weeks ago

Confirmed it's caused by viewing images. How do I disable image viewing? Didn't see any command line or config option for that.

danschwarz commented 4 weeks ago

Ah, I may not have added an option to disable image viewing. I'll have to add an option for that. Meanwhile, you can disable images by removing the term-image package, and it'll disable automatically. But before you do that...

I'm still trying to figure out what version of term-image and what version of urwid you have installed in your environment. I'm not familiar with how brew works, as all my dependencies install via pip. The latest versions are term-image 0.7.1 and urwid 2.6.12, and it'd be helpful to test with these versions (especially the latest term-image version) to see if the crash persists.