python: Fix remaining bare excepts in codebase.

Fixes #2862.
This commit is contained in:
sinwar 2017-03-05 14:55:27 +05:30 committed by Tim Abbott
parent 08e1759ad0
commit 6f0564e9f4
17 changed files with 25 additions and 25 deletions

View File

@ -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)

View File

@ -234,7 +234,7 @@ class ZulipToJabberBot(object):
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)

View File

@ -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')

View File

@ -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'
@ -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')

View File

@ -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

View File

@ -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()

View File

@ -404,7 +404,7 @@ try:
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

View File

@ -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()

View File

@ -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
@ -553,7 +553,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
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.
@ -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

View File

@ -27,7 +27,7 @@ class _RateLimitFilter(object):
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:

View File

@ -146,14 +146,14 @@ def has_request_variables(view_func):
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)

View File

@ -31,7 +31,7 @@ class Command(BaseCommand):
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)

View File

@ -50,7 +50,7 @@ class Command(BaseCommand):
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)

View File

@ -230,7 +230,7 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
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())
@ -247,7 +247,7 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
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())
@ -281,7 +281,7 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
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())

View File

@ -15,7 +15,7 @@ try:
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

View File

@ -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)

View File

@ -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)