ihabunek / toot

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

TUI: Crash when loading a specific account #499

Open ArthurHoaro opened 2 months ago

ArthurHoaro commented 2 months ago

This error happens when I try to open this account from a post in the main timeline, using "A".

It looks the same as this issue (solved), but for an account and not a post. I'm guessing it's because of accented characters in the profile/hashtags.

Account: @juliette@mastodon.green From post: https://mastodon.green/@juliette/113039496315816199

 ➜ toot env         
toot 0.44.1
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0]
Linux-5.15.0-119-generic-x86_64-with-glibc2.35

Stacktrace:

Traceback (most recent call last):
  File "/home/arthur/.local/bin/toot", line 8, in <module>
    sys.exit(cli())
  File "/home/arthur/.local/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/arthur/.local/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/arthur/.local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/arthur/.local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/arthur/.local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/arthur/.local/lib/python3.10/site-packages/toot/cli/__init__.py", line 124, in wrapped
    return f(get_context(), *args, **kwargs)
  File "/home/arthur/.local/lib/python3.10/site-packages/toot/cli/tui.py", line 73, in tui
    tui.run()
  File "/home/arthur/.local/lib/python3.10/site-packages/toot/tui/app.py", line 164, in run
    self.loop.run()
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/main_loop.py", line 337, in run
    self._run()
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/main_loop.py", line 439, in _run
    self.event_loop.run()
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/asyncio_loop.py", line 235, in run
    raise exc.with_traceback(exc.__traceback__)
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/asyncio_loop.py", line 114, in _entering_idle
    callback()
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/main_loop.py", line 650, in entering_idle
    self.draw_screen()
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/event_loop/main_loop.py", line 667, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/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 "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/overlay.py", line 907, in render
    top_c = self.top_w.render(self.top_w_size(real_size, left, right, top, bottom), focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 711, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/pile.py", line 873, in render
    canv = w.render(w_size, focus=focus and item_focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/columns.py", line 1026, in render
    w.render(w_size, focus=focus and self.focus_position == i),
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/listbox.py", line 754, in render
    canvas = widget.render((maxcol,))
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 112, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/pile.py", line 873, in render
    canv = w.render(w_size, focus=focus and item_focus)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 113, in cached_render
    validate_size(self, size, canv)
  File "/home/arthur/.local/lib/python3.10/site-packages/urwid/widget/widget.py", line 92, in validate_size
    raise WidgetError(
urwid.widget.widget.WidgetError: Widget <TextEmbed fixed/flow widget 'slow living in denmark. interests include \uf8fe\uf8ff\uf8ff\uf8ff\uf8ff\uf8ff\uf8ff, \uf...d \uf8fe\uf8ff\uf8ff\uf8ff\uf8ff.\u2029she/her'> rendered (224 x 1) canvas when passed size (225,)!
danschwarz commented 2 months ago

please provide output of toot diag command. I want to see what versions of urwidgets and urwid you are running.

ArthurHoaro commented 2 months ago
 ➜ toot diag        
## Toot Diagnostics

Current Date/Time: 2024-08-28 16:29:26 UTC
Toot version: 0.44.1
Platform: Linux-5.15.0-119-generic-x86_64-with-glibc2.35
Distro: Ubuntu 22.04.4 LTS
Python version: 3.10.12

Dependency versions:
 * beautifulsoup4: 4.10.0
 * click: 8.1.7
 * flake8: 7.0.0
 * pillow: 10.4.0
 * pytest: not installed
 * requests: 2.25.1
 * setuptools: 72.1.0
 * term-image: 0.7.2
 * tomlkit: 0.13.0
 * typing-extensions: 4.12.2
 * urwid: 2.6.15
 * urwidgets: 0.2.0
 * vermin: not installed
 * wcwidth: 0.2.5

Settings file path: /home/arthur/.config/toot/settings.toml
Config file path: /home/arthur/.config/toot/config.json
danschwarz commented 2 months ago

@AnonymouX47 this is with Urwidgets 0.2.0, any thoughts?

AnonymouX47 commented 2 months ago

Hello!

I looked into the issue and found out it was due to the presence of the U+2029 (Paragraph Separator) codepoint in the user's bio (between "." and "she/her"), as I initially suspected. This is a really uncommon edge case but still deserves attention.

So, I dug further and realised the exception raised was due to the use of urwid.Text.pack() (which happens to be buggy with the use of Unicode line breaks; reported in https://github.com/urwid/urwid/issues/924) for width computation by TextEmbed.

I've now switched to using urwid.calc_width() instead and released v0.2.1. This issue should now be fixed with the new version.

Thank you very much. :smiley: