Skip to content

Commit

Permalink
Merge pull request #1779 from sopel-irc/updater-error-handling
Browse files Browse the repository at this point in the history
find_updates: error handling
  • Loading branch information
dgw authored Dec 9, 2019
2 parents b8af8af + 951fcca commit 684a848
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions sopel/modules/find_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,45 @@ def startup_version_check(bot, trigger):
check_version(bot)


def _check_succeeded(bot):
bot.memory['update_failures'] = 0


def _check_failed(bot):
bot.memory['update_failures'] = 1 + bot.memory.get('update_failures', 0)


@sopel.module.interval(wait_time)
def check_version(bot):
version = sopel.version_info
success = False

try:
r = requests.get(version_url, timeout=(5, 5))
except requests.exceptions.RequestException:
_check_failed(bot)
else:
success = True

try:
if success:
info = r.json()
except ValueError:
# TODO: use JSONDecodeError when dropping Pythons < 3.5
_check_failed(bot)

if not success and bot.memory.get('update_failures', 0) > 4:
bot.say("I haven't been able to check for updates in a while. "
"Please verify that {} is working and I can reach it."
.format(version_url), bot.config.core.owner)
bot.say("If this issue persists, please alert the Sopel dev team in "
"#sopel on freenode, or open a GitHub issue: "
"https://github.com/sopel-irc/sopel/issues",
bot.config.core.owner)
return

_check_succeeded(bot)

# TODO: Python3 specific. Disable urllib warning from config file.
# requests.packages.urllib3.disable_warnings()
info = requests.get(version_url).json()
if version.releaselevel == 'final':
latest = info['version']
notes = info['release_notes']
Expand Down

0 comments on commit 684a848

Please sign in to comment.