dronefly-garden / dronefly

Red Discord Bot V3 cogs for naturalists.
Other
16 stars 3 forks source link

iNat last: handle no results gracefully #58

Closed synrg closed 4 years ago

synrg commented 4 years ago

Spotted in log from new server using the bot: if you are on a channel where [p]inat last has no matching messages in its history, it fail with an error to the user & traceback in the log like:

[2019-12-11 08:21:07] [ERROR] red: Exception in command 'inat last'
Traceback (most recent call last):
  File "/home/synrg/.local/share/Appledore/cogs/CogManager/cogs/inatcog/last.py", line 43, in get_last_obs_msg
    m for m in msgs if not m.author.bot and re.search(PAT_OBS_LINK, m.content)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/synrg/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/synrg/.local/share/Appledore/cogs/CogManager/cogs/inatcog/inatcog.py", line 156, in last
    last = await inat_link_msg.get_last_obs_msg(msgs)
RuntimeError: coroutine raised StopIteration

Clearly, [p]inat last just has to catch StopIteration & gracefully return Not found. Should be an easy fix.

synrg commented 4 years ago

Closed by 74aab59dfa9d851efffaa67a39138c305ca36485 .