Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes two gaps in the
currency
plugin's error handling:KeyError
was not handled. Such an exception could result if the exchange rate API returns valid JSON that doesn't contain the expected keys (perhaps an error reply).rates_updated
was refreshed before executing all code that could prematurely terminate the update operation, leading to some (but not all) of the data being stale for at least 24 hours until the next fullupdate_rates()
run.Additionally, catching
KeyError
will allow the bot to continue converting the input as normal if it has rates cached.Checklist
make qa
(runsmake quality
andmake test
)test/modules/test_modules_currency.py
that explicitly feeds it bad JSON (invalid, missing expected keys, etc.) to verify that the error handling works as expected.Notes
Discovered point 1 above when I ran the
.cur
command for the first time in a while and it presumably tried to update the exchange rates, but couldn't findrates_fiat['rates']
. Running the command again succeeded, hence my decision to add "Try again later." as part of the revised error message.Possible future enhancement: adding a note to the conversion output if the cached rates are older than 2-3x the refresh interval.