Skip to content

Commit 787baa6

Browse files
authored
Merge pull request #2235 from Exirel/isup-reply-error-message-value-error
isup: catch up errors from get site and from requests differently
2 parents d36a19d + 96d37e5 commit 787baa6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ xmltodict==0.12
22
pytz
33
praw>=4.0.0,<6.0.0
44
geoip2>=4.0,<5.0
5-
requests>=2.0.0,<3.0.0
5+
requests>=2.24.0,<3.0.0
66
dnspython<3.0
77
sqlalchemy>=1.4,<1.5

sopel/modules/isup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ def handle_isup(bot, trigger, secure=True):
5959
"""
6060
try:
6161
site = get_site_url(trigger.group(2))
62-
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
63-
response.raise_for_status()
6462
except ValueError as error:
6563
bot.reply(str(error))
64+
return
65+
66+
try:
67+
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
68+
response.raise_for_status()
6669
except requests.exceptions.SSLError:
6770
bot.say(
6871
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
@@ -83,6 +86,8 @@ def handle_isup(bot, trigger, secure=True):
8386
bot.say(
8487
'{} looks down to me (connection error).'
8588
.format(site))
89+
except ValueError:
90+
bot.reply('"{}" is not a valid URL.'.format(site))
8691
else:
8792
# If no exception happened, the request must have succeeded.
8893
bot.say(site + ' looks fine to me.')

test/modules/test_modules_isup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock):
114114
"""Test URL that can't be parsed."""
115115
requests_mock.head(
116116
'http://.foo',
117-
exc=ValueError("Failed to parse: '.foo', label empty or too long"),
117+
exc=ValueError("Invalid URL"),
118118
)
119119

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

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

128128

0 commit comments

Comments
 (0)