ihabunek / toot

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

[toot tui] ApiError Exception when trying to favorite a boosted toot #206

Open fmaida opened 2 years ago

fmaida commented 2 years ago

I'm using Toot tui v0.28 and browsing from the italian Mastodon instance "livellosegreto.it"

I'm no Mastodon expert so I'm not sure if I can explain with the right words the issue I'm actually experiencing: I'm trying to favorite a boosted(/retweeted) toot.

_

1) The first time I try to press the "F" key, the yellow star does not appear on the interface after date and time.

2) The second time I try to press the "F" key on the same toot, I'm getting a ApiError exception:

  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/tui/app.py", line 433, in _favourite
    api.favourite(self.app, self.user, status.id)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/api.py", line 133, in favourite
    return _status_action(app, user, status_id, 'favourite')
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/api.py", line 24, in _status_action
    return http.post(app, user, url).json()
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/http.py", line 75, in post
    return process_response(response)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/http.py", line 45, in process_response
    raise ApiError(error)
toot.exceptions.ApiError: Validazione fallita: Status è già presente

("Validazione fallita: Status è già presente" in italian means "Failed validation: Status is already present")

Traceback (most recent call last):
  File "/usr/local/bin/toot", line 33, in <module>
    sys.exit(load_entry_point('toot==0.28.0', 'console_scripts', 'toot')())
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/console.py", line 560, in main
    run_command(app, user, command_name, args)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/console.py", line 542, in run_command
    return fn(app, user, parsed_args)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/commands.py", line 347, in tui
    TUI.create(app, user).run()
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/tui/app.py", line 116, in run
    self.loop.run()
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 287, in run
    self._run()
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 385, in _run
    self.event_loop.run()
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 1494, in run
    reraise(*exc_info)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/compat.py", line 58, in reraise
    raise value
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/raw_display.py", line 416, in <lambda>
    wrapper = lambda: self.parse_input(
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/raw_display.py", line 515, in parse_input
    callback(processed, processed_codes)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 412, in _update
    self.process_input(keys)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 519, in process_input
    something_handled |= bool(self.unhandled_input(k))
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/urwid/main_loop.py", line 565, in unhandled_input
    return self._unhandled_input(input)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/tui/app.py", line 512, in unhandled_input
    self.show_exception(self.exception)
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/tui/app.py", line 337, in show_exception
    widget=ExceptionStackTrace(exception),
  File "/usr/local/Cellar/toot/0.28.0_1/libexec/lib/python3.10/site-packages/toot/tui/overlays.py", line 40, in __init__
    lines = traceback.format_exception(etype=type(ex), value=ex, tb=ex.__traceback__)
TypeError: format_exception() got an unexpected keyword argument 'etype'
danschwarz commented 1 year ago

There are two issues going on here, the main issue is the fact that Mastodon servers return a 422 error when trying to favorite a toot already favorited or boost a post already boosted. Toot throws an exception in that case, where imho it should ignore the error. Second issue is that the exception displaying code in Toot need an update to be compatible with Python 3.10+. I have two pull requests addressing both of these issues; the main one is https://github.com/ihabunek/toot/pull/261