Skip to content

Commit 5ad5350

Browse files
committed
Replace try..except:pass statements with more specific exception handling in grab.py
1 parent 0cbbad1 commit 5ad5350

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

plugins/grab.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def moregrab(text, chan):
5959
index = ""
6060
try:
6161
index = int(text)
62-
except:
62+
except ValueError:
6363
return "Please specify an integer value."
6464
if abs(int(index)) > len(search_pages[chan]) or index == 0:
6565
return "please specify a valid page number between 1 and {}.".format(len(search_pages[chan]))
@@ -79,7 +79,7 @@ def check_grabs(name, quote, chan):
7979
return True
8080
else:
8181
return False
82-
except:
82+
except KeyError:
8383
return False
8484

8585

@@ -131,7 +131,7 @@ def lastgrab(text, chan, message):
131131
lgrab = ""
132132
try:
133133
lgrab = grab_cache[chan][text.lower()][-1]
134-
except:
134+
except (KeyError, IndexError):
135135
return "<{}> has never been grabbed.".format(text)
136136
if lgrab:
137137
quote = lgrab
@@ -152,11 +152,11 @@ def grabrandom(text, chan, message):
152152
else:
153153
try:
154154
name = random.choice(list(grab_cache[chan].keys()))
155-
except:
155+
except KeyError:
156156
return "I couldn't find any grabs in {}.".format(chan)
157157
try:
158158
grab = random.choice(grab_cache[chan][name.lower()])
159-
except:
159+
except KeyError:
160160
return "it appears {} has never been grabbed in {}".format(name, chan)
161161
if grab:
162162
message(format_grab(name, grab), chan)
@@ -175,8 +175,8 @@ def grabsearch(text, chan):
175175
quotes = grab_cache[chan][text.lower()]
176176
for grab in quotes:
177177
result.append((text, grab))
178-
except:
179-
pass
178+
except KeyError:
179+
pass
180180
for name in grab_cache[chan]:
181181
for grab in grab_cache[chan][name]:
182182
if name != text.lower():

0 commit comments

Comments
 (0)