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

isup: catch up errors from get site and from requests differently #2235

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ xmltodict==0.12
pytz
praw>=4.0.0,<6.0.0
geoip2>=4.0,<5.0
requests>=2.0.0,<3.0.0
requests>=2.24.0,<3.0.0
dnspython<3.0
sqlalchemy>=1.4,<1.5
9 changes: 7 additions & 2 deletions sopel/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ def handle_isup(bot, trigger, secure=True):
"""
try:
site = get_site_url(trigger.group(2))
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
except ValueError as error:
bot.reply(str(error))
return

try:
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
except requests.exceptions.SSLError:
bot.say(
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
Expand All @@ -83,6 +86,8 @@ def handle_isup(bot, trigger, secure=True):
bot.say(
'{} looks down to me (connection error).'
.format(site))
except ValueError:
bot.reply('"{}" is not a valid URL.'.format(site))
else:
# If no exception happened, the request must have succeeded.
bot.say(site + ' looks fine to me.')
Expand Down
4 changes: 2 additions & 2 deletions test/modules/test_modules_isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock):
"""Test URL that can't be parsed."""
requests_mock.head(
'http://.foo',
exc=ValueError("Failed to parse: '.foo', label empty or too long"),
exc=ValueError("Invalid URL"),
)

irc.pm(user, '.isup .foo')

assert len(bot.backend.message_sent) == 1, (
'.isup command should output exactly one line')
assert bot.backend.message_sent == rawlist(
'PRIVMSG User :User: Failed to parse: \'.foo\', label empty or too long'
'PRIVMSG User :User: "http://.foo" is not a valid URL.'
)


Expand Down