Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_updates: error handling #1779

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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