Skip to content

Commit

Permalink
python: Fix remaining bare excepts in codebase.
Browse files Browse the repository at this point in the history
Fixes zulip#2862.
  • Loading branch information
sinwar authored and timabbott committed Mar 6, 2017
1 parent 08e1759 commit 6f0564e
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/integrations/google/google-calendar
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ for i in itertools.count():
if not i % 10:
populate_events()
send_reminders()
except:
except Exception:
logging.exception("Couldn't download Google calendar and/or couldn't post to Zulip.")
time.sleep(60)
2 changes: 1 addition & 1 deletion bots/jabber_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def process_event(self, event):
self.stream_message(message)
elif message['type'] == 'private':
self.private_message(message)
except:
except Exception:
logging.exception("Exception forwarding Zulip => Jabber")
elif event['type'] == 'subscription':
self.process_subscription(event)
Expand Down
2 changes: 1 addition & 1 deletion tools/compile-handlebars-templates
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run_forever():
run()
remove_error_stamp_file(error_file_path)
print('done')
except:
except Exception:
add_error_stamp_file(error_file_path)
print('\n\n\n\033[91mPLEASE FIX!!\033[0m\n\n')

Expand Down
8 changes: 4 additions & 4 deletions tools/create-test-api-docs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def encode_info(info):
try:
info = ujson.loads(info)
result = '(stringified)\n'
except:
except Exception:
pass
result += cgi.escape(pprint.pformat(info, indent=4))
return '<pre>' + result + '</pre>'
except:
except Exception:
pass
try:
return cgi.escape(str(info))
except:
except Exception:
pass
return 'NOT ENCODABLE'

Expand All @@ -80,7 +80,7 @@ def create_single_page(pattern, out_dir, href, calls):
f.write('<div class="test">')
try:
f.write(call['url'])
except:
except Exception:
f.write(call['url'].encode('utf8'))
f.write('<br>\n')
f.write(call['method'] + '<br>\n')
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def server_is_up(server, log_file):
try:
# We could get a 501 error if the reverse proxy is up but the Django app isn't.
return requests.get('http://127.0.0.1:9981/accounts/home').status_code == 200
except:
except Exception:
return False

@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion tools/review
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def review_pr():
# type: () -> None
try:
pull_id = int(sys.argv[1])
except:
except Exception:
exit('please provide an integer pull request id')

ensure_on_clean_master()
Expand Down
2 changes: 1 addition & 1 deletion tools/run-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def shutdown_handler(*args, **kwargs):
for s in (signal.SIGINT, signal.SIGTERM):
signal.signal(s, shutdown_handler)
ioloop.start()
except:
except Exception:
# Print the traceback before we get SIGTERM and die.
traceback.print_exc()
raise
Expand Down
2 changes: 1 addition & 1 deletion zerver/lib/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def compute_mit_user_fullname(email):
return match_user.group(1).lower() + "@" + match_user.group(2).upper()[1:]
except DNS.Base.ServerError:
pass
except:
except Exception:
print("Error getting fullname for %s:" % (email,))
traceback.print_exc()
return email.lower()
Expand Down
6 changes: 3 additions & 3 deletions zerver/lib/bugdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def fetch_open_graph_image(url):
# TODO: What if response content is huge? Should we get headers first?
try:
content = requests.get(url, timeout=1).text
except:
except Exception:
return None

# Extract the head and meta tags
Expand Down Expand Up @@ -553,7 +553,7 @@ def twitter_link(self, url):
img.set('src', media_url)

return tweet
except:
except Exception:
# We put this in its own try-except because it requires external
# connectivity. If Twitter flakes out, we don't want to not-render
# the entire message; we just want to not show the Twitter preview.
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def do_convert(content, message=None, message_realm=None, possible_words=None, s
# Sometimes Python-Markdown is really slow; see
# https://trac.zulip.net/ticket/345
return timeout(5, _md_engine.convert, content)
except:
except Exception:
from zerver.lib.actions import internal_send_message
from zerver.models import get_user_profile_by_email

Expand Down
2 changes: 1 addition & 1 deletion zerver/lib/logging_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def filter(self, record):
try:
cache.set('RLF_TEST_KEY', 1, 1)
use_cache = cache.get('RLF_TEST_KEY') == 1
except:
except Exception:
use_cache = False

if use_cache:
Expand Down
4 changes: 2 additions & 2 deletions zerver/lib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ def _wrapped_view_func(request, *args, **kwargs):
val = param.converter(val)
except JsonableError:
raise
except:
except Exception:
raise RequestVariableConversionError(param.post_var_name, val)

# Validators are like converters, but they don't handle JSON parsing; we do.
if param.validator is not None and not default_assigned:
try:
val = ujson.loads(val)
except:
except Exception:
raise JsonableError(_('argument "%s" is not valid json.') % (param.post_var_name,))

error = param.validator(param.post_var_name, val)
Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/check_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _check_within_range(self, key, count_func, trim_func=None):
user_id = int(key.split(':')[1])
try:
user = get_user_profile_by_id(user_id)
except:
except Exception:
user = None
max_calls = max_api_calls(user=user)

Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def handle(self, *args, **options):
else:
try:
user_profile = UserProfile.objects.get(api_key=options['api_key'])
except:
except Exception:
print("Unable to get user profile for api key %s" % (options['api_key'],))
exit(1)

Expand Down
6 changes: 3 additions & 3 deletions zerver/tornado/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def get_response(self, request):
try:
callback, param_dict = resolver.resolve404()
response = callback(request, **param_dict)
except:
except Exception:
try:
response = self.handle_uncaught_exception(request, resolver,
sys.exc_info())
Expand All @@ -247,7 +247,7 @@ def get_response(self, request):
try:
callback, param_dict = resolver.resolve403()
response = callback(request, **param_dict)
except:
except Exception:
try:
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
Expand Down Expand Up @@ -281,7 +281,7 @@ def apply_response_middleware(self, request, response, resolver):
response = middleware_method(request, response)
if hasattr(self, 'apply_response_fixes'):
response = self.apply_response_fixes(request, response)
except: # Any exception should be gathered and handled
except Exception: # Any exception should be gathered and handled
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

Expand Down
2 changes: 1 addition & 1 deletion zerver/tornado/ioloop_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def instrument_tornado_ioloop():
# type: () -> None
ioloop._poll = InstrumentedPoll # type: ignore # cross-version type variation is hard for mypy
except:
except Exception:
# Tornado 3
from tornado.ioloop import IOLoop, PollIOLoop
# There isn't a good way to get at what the underlying poll implementation
Expand Down
2 changes: 1 addition & 1 deletion zerver/webhooks/pagerduty/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def api_pagerduty_webhook(request, user_profile, client, payload=REQ(argument_ty

try:
format_dict = build_pagerduty_formatdict(message)
except:
except Exception:
send_raw_pagerduty_json(user_profile, client, stream, message, topic)
else:
send_formated_pagerduty(user_profile, client, stream, message_type, format_dict, topic)
Expand Down
2 changes: 1 addition & 1 deletion zerver/webhooks/pivotal/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def api_pivotal_webhook(request, user_profile, client, stream=REQ()):
subject, content = api_pivotal_webhook_v3(request, user_profile, stream)
except AttributeError:
return json_error(_("Failed to extract data from Pivotal XML response"))
except:
except Exception:
# Attempt to parse v5 JSON payload
try:
subject, content = api_pivotal_webhook_v5(request, user_profile, stream)
Expand Down

0 comments on commit 6f0564e

Please sign in to comment.