Skip to content

Commit

Permalink
Modernize exception syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Feb 4, 2014
1 parent d479b3a commit 8b1b872
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/sentry/__init__.py
Expand Up @@ -11,7 +11,7 @@
try:
VERSION = __import__('pkg_resources') \
.get_distribution('sentry').version
except Exception, e:
except Exception as e:
VERSION = 'unknown'


Expand Down
10 changes: 5 additions & 5 deletions src/sentry/coreapi.py
Expand Up @@ -168,7 +168,7 @@ def decode_and_decompress_data(encoded_data):
return decompress(encoded_data)
except zlib.error:
return base64.b64decode(encoded_data)
except Exception, e:
except Exception as e:
# This error should be caught as it suggests that there's a
# bug somewhere in the client's code.
logger.info(e, **client_metadata(exception=e))
Expand All @@ -179,7 +179,7 @@ def decode_and_decompress_data(encoded_data):
def safely_load_json_string(json_string):
try:
obj = json.loads(json_string)
except Exception, e:
except Exception as e:
# This error should be caught as it suggests that there's a
# bug somewhere in the client's code.
logger.info(e, **client_metadata(exception=e))
Expand Down Expand Up @@ -268,7 +268,7 @@ def validate_data(project, data, client=None):
if 'timestamp' in data:
try:
process_data_timestamp(data)
except InvalidTimestamp, e:
except InvalidTimestamp as e:
# Log the error, remove the timestamp, and continue
logger.info(
'Discarded invalid value for timestamp: %r', data['timestamp'],
Expand Down Expand Up @@ -368,7 +368,7 @@ def validate_data(project, data, client=None):
inst = interface(value)
inst.validate()
data[import_path] = inst.serialize()
except Exception, e:
except Exception as e:
if isinstance(e, AssertionError):
log = logger.info
else:
Expand All @@ -381,7 +381,7 @@ def validate_data(project, data, client=None):
# assume it's something like 'warning'
try:
data['level'] = LOG_LEVEL_REVERSE_MAP[level]
except KeyError, e:
except KeyError as e:
logger.info(
'Discarded invalid logger value: %s', level,
**client_metadata(client, project, exception=e))
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/db/models/fields/gzippeddict.py
Expand Up @@ -31,7 +31,7 @@ def to_python(self, value):
if isinstance(value, basestring) and value:
try:
value = pickle.loads(decompress(value))
except Exception, e:
except Exception as e:
logger.exception(e)
return {}
elif not value:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/db/models/fields/node.py
Expand Up @@ -97,7 +97,7 @@ def to_python(self, value):
if isinstance(value, basestring) and value:
try:
value = pickle.loads(decompress(value))
except Exception, e:
except Exception as e:
logger.exception(e)
value = {}
elif not value:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/manager.py
Expand Up @@ -428,7 +428,7 @@ def save_data(self, project, data, raw=False):
# TODO: should we mail admins when there are failures?
try:
logger.exception(u'Unable to process log entry: %s', exc)
except Exception, exc:
except Exception as exc:
warnings.warn(u'Unable to process log entry: %s', exc)
return

Expand Down Expand Up @@ -573,7 +573,7 @@ def _create_group(self, event, tags=None, **kwargs):

try:
self.add_tags(group, tags)
except Exception, e:
except Exception as e:
logger.exception('Unable to record tags: %s' % (e,))

return group, is_new, is_sample
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/activity.py
Expand Up @@ -150,6 +150,6 @@ def send_notification(self):

try:
msg.send()
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.mail.errors')
logger.exception(e)
2 changes: 1 addition & 1 deletion src/sentry/models/pendingteammember.py
Expand Up @@ -67,6 +67,6 @@ def send_invite_email(self):

try:
msg.send([self.email])
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.mail.errors')
logger.exception(e)
2 changes: 1 addition & 1 deletion src/sentry/plugins/base.py
Expand Up @@ -76,7 +76,7 @@ def first(self, func_name, *args, **kwargs):
for plugin in self.all():
try:
result = getattr(plugin, func_name)(*args, **kwargs)
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.plugins')
logger.error('Error processing %s() on %r: %s', func_name, plugin.__class__, e, extra={
'func_arg': args,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/bases/issue.py
Expand Up @@ -173,7 +173,7 @@ def view(self, request, group, **kwargs):
form_data=form.cleaned_data,
request=request,
)
except forms.ValidationError, e:
except forms.ValidationError as e:
form.errors['__all__'] = [u'Error creating issue: %s' % e]

if form.is_valid():
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/replays.py
Expand Up @@ -34,7 +34,7 @@ def replay(self):
conn.request(self.method, full_url, data, self.headers or {})

response = conn.getresponse()
except socket.error, e:
except socket.error as e:
return {
'status': 'error',
'reason': str(e),
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/tasks/store.py
Expand Up @@ -24,7 +24,7 @@ def preprocess_event(data, **kwargs):
if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data['platform'] == 'javascript':
try:
expand_javascript_source(data)
except Exception, e:
except Exception as e:
logger.exception(u'Error fetching javascript source: %s', e)
finally:
save_event.delay(data=data)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/utils/cache.py
Expand Up @@ -63,7 +63,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
try:
self.cache.delete(self.lock_key)
except Exception, e:
except Exception as e:
logger.exception(e)


Expand Down
2 changes: 1 addition & 1 deletion src/sentry/utils/safe.py
Expand Up @@ -17,7 +17,7 @@
def safe_execute(func, *args, **kwargs):
try:
result = func(*args, **kwargs)
except Exception, e:
except Exception as e:
transaction.rollback_unless_managed()
if hasattr(func, 'im_class'):
cls = func.im_class
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/web/api.py
Expand Up @@ -197,7 +197,7 @@ def _dispatch(self, request, project_id=None, *args, **kwargs):

try:
project_, user = project_from_auth_vars(auth_vars)
except APIError, error:
except APIError as error:
return HttpResponse(unicode(error.msg), status=error.http_status)
else:
if user:
Expand Down Expand Up @@ -231,7 +231,7 @@ def _dispatch(self, request, project_id=None, *args, **kwargs):
try:
response = super(APIView, self).dispatch(request, project=project, auth=auth, **kwargs)

except APIError, error:
except APIError as error:
response = HttpResponse(unicode(error.msg), content_type='text/plain', status=error.http_status)

if origin:
Expand Down Expand Up @@ -316,7 +316,7 @@ def process(self, request, project, auth, data, **kwargs):
try:
# mutates data
validate_data(project, data, auth.client)
except InvalidData, e:
except InvalidData as e:
raise APIError(u'Invalid data: %s (%s)' % (unicode(e), type(e)))

# mutates data
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/web/frontend/admin.py
Expand Up @@ -161,7 +161,7 @@ def create_new_user(request):
body, settings.SERVER_EMAIL, [user.email],
fail_silently=False
)
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.mail.errors')
logger.exception(e)

Expand Down Expand Up @@ -339,7 +339,7 @@ def status_mail(request):
body, settings.SERVER_EMAIL, [request.user.email],
fail_silently=False
)
except Exception, e:
except Exception as e:
form.errors['__all__'] = [unicode(e)]

return render_to_response('sentry/admin/status/mail.html', {
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/web/frontend/groups.py
Expand Up @@ -53,7 +53,7 @@ def _get_group_list(request, project):
for cls in get_filters(Group, project):
try:
filters.append(cls(request, project))
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.filters')
logger.exception('Error initializing filter %r: %s', cls, e)

Expand All @@ -71,7 +71,7 @@ def _get_group_list(request, project):
if not filter_.is_set():
continue
event_list = filter_.get_query_set(event_list)
except Exception, e:
except Exception as e:
logger = logging.getLogger('sentry.filters')
logger.exception('Error processing filter %r: %s', cls, e)

Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/web/views.py
Expand Up @@ -28,6 +28,6 @@ def logging_request_exc(request):
logger = logging.getLogger('sentry.test')
try:
raise Exception(request.GET.get('message', 'view exception'))
except Exception, e:
except Exception as e:
logger.error(e, exc_info=True, extra={'request': request})
return HttpResponse('')

0 comments on commit 8b1b872

Please sign in to comment.