ihabunek / toot

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

videos from peertube cause traceback when shown in toot timeline #414

Closed lilmike closed 1 year ago

lilmike commented 1 year ago

Hiya,

If you follow a peertube channel, whenever a video is posted, the status will cause toot to traceback as such:

Traceback (most recent call last):
  File "/usr/bin/toot", line 33, in <module>
    sys.exit(load_entry_point('toot==0.36.0', 'console_scripts', 'toot')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/toot/console.py", line 823, in main
    run_command(app, user, command_name, args)
  File "/usr/lib/python3.11/site-packages/toot/console.py", line 804, in run_command
    return fn(app, user, parsed_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/toot/commands.py", line 57, in timeline
    print_timeline(items)
  File "/usr/lib/python3.11/site-packages/toot/output.py", line 314, in print_timeline
    print_status(item, width)
  File "/usr/lib/python3.11/site-packages/toot/output.py", line 236, in print_status
    time = parse_datetime(status['created_at'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/toot/tui/utils.py", line 28, in parse_datetime
    dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

Thanks,

-Michael.

P.S. I'm using pleroma, and toot from latest git.

ihabunek commented 1 year ago

That stack trace looks like it was created by an older version of toot. Could you git pull the new code and try again? I'm suspecting it may crash again though. Don't have a pleroma subcription to try out.

lilmike commented 1 year ago

Here you go, traceback from latest git:

Traceback (most recent call last):
  File "/home/vlilmike/.pyenv/versions/toot/bin/toot", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/console.py", line 961, in main
    run_command(app, user, command_name, args)
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/console.py", line 943, in run_command
    return fn(app, user, parsed_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/commands.py", line 60, in timeline
    statuses = [from_dict(Status, item) for item in items]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/commands.py", line 60, in <listcomp>
    statuses = [from_dict(Status, item) for item in items]
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 394, in from_dict
    return cls(**dict(_fields()))
                 ^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 392, in _fields
    yield field.name, _convert(field_type, value)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 415, in _convert
    return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

-Michael.

ihabunek commented 1 year ago

I tried to reproduce, even signed up for a pleroma instance, but without luck. I added some code which should produce a better error message. Could you pull latest from master and tell me what error you get now?

lilmike commented 1 year ago

Here's the new output:

Traceback (most recent call last):
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 430, in _convert_with_error_handling
    return _convert(field_type, field_value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 445, in _convert
    return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z").astimezone()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vlilmike/.pyenv/versions/toot/bin/toot", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/console.py", line 961, in main
    run_command(app, user, command_name, args)
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/console.py", line 943, in run_command
    return fn(app, user, parsed_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/commands.py", line 60, in timeline
    statuses = [from_dict(Status, item) for item in items]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/commands.py", line 60, in <listcomp>
    statuses = [from_dict(Status, item) for item in items]
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 410, in from_dict
    return cls(**dict(_fields()))
                 ^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 407, in _fields
    converted = _convert_with_error_handling(cls, field.name, field_type, value)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlilmike/.pyenv/versions/3.11.6/envs/toot/lib/python3.11/site-packages/toot/entities.py", line 434, in _convert_with_error_handling
    raise ConversionError(data_class, field_name, field_type, field_value)
toot.entities.ConversionError: Failed converting field `Status.created_at` of type `datetime` from value ''

For reference, the channel I am following is mwtab_main@peertube.fedihost.website

-Michael.

ihabunek commented 1 year ago

This is a bug in pleroma, they return an empty string for created_at (not even null) which should always be populated. I'll create a workaround for this.

Possibly related to https://git.pleroma.social/pleroma/pleroma/-/issues/2851

ihabunek commented 1 year ago

I added a hack for now, it will display current datetime instead. Please pull and test.

lilmike commented 1 year ago

It definitely doesn't crash now.

-Michael.

-- Sorry about the test, it's just a me thing. Michael Taboada, Creator of Games. Does that make me a god, well, sorta. My pgp key: 79BC390E8864CD71305D4DD606CD2197A6EE5ED7 My website: https://michaels.world 2MB website: https://2mb.games Don't believe everything you read on the internet. I might not be real, you might not be real, and this email certainly isn't real. Sent from my christmas spirited... stationary bicycle