When a species count is indicated as 'X', howMany is not set in any transactions returned by the API. This caused `ebird hybrids CA-NS 7' to fail yesterday when the command attempted to format the output assuming howMany was set.
Exception in command 'ebird hybrids'
Traceback (most recent call last):
File "/home/synrg/.local/lib/python3.8/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/ebirdcog/ebirdcog.py", line 133, in hybrids
value=("· {obsDt}: {howMany} at {locName}").format_map(rec),
File "/home/synrg/.local/share/Appledore/cogs/CogManager/cogs/ebirdcog/ebirdcog.py", line 26, in __getitem__
val = super().__getitem__(key)
KeyError: 'howMany'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/synrg/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "/home/synrg/.local/lib/python3.8/site-packages/redbot/core/commands/commands.py", line 631, in invoke
await super().invoke(ctx)
File "/home/synrg/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1158, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "/home/synrg/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/synrg/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'howMany'
A quick fix would be to set rec["howMany"] = "uncounted" prior to formatting the string.
A more thorough approach would be to wrap the API results in dataclasses-json as we do for inatcog so that each record always has appropriate values even when not returned by the API call.
When a species count is indicated as 'X', howMany is not set in any transactions returned by the API. This caused `ebird hybrids CA-NS 7' to fail yesterday when the command attempted to format the output assuming howMany was set.
A quick fix would be to set
rec["howMany"] = "uncounted"
prior to formatting the string.A more thorough approach would be to wrap the API results in dataclasses-json as we do for
inatcog
so that each record always has appropriate values even when not returned by the API call.