Skip to content

Commit

Permalink
Py3 exception logging, issue #17
Browse files Browse the repository at this point in the history
Previous commit didn't verify logging of exceptions.

Critical issues:
- types.TypeType is now built-in, added legacy switch
- filter yields `TypeError: 'filter' object is not subscriptable`,
changed to list comprehension (since it was used already the previous
line)

2to3 also complained the use of map over list comprehension, changed for
similar rationale.
  • Loading branch information
lusitania committed Oct 5, 2014
1 parent 2a11ea0 commit 4d25174
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion airbrake/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def airbrake_error_from_logrecord(record):
# find params from kwarg 'extra'
# See "The second keyword argument is extra"
# - https://docs.python.org/2/library/logging.html#logging.Logger.debug
for key, val in vars(record).items():
for key, val in list(vars(record).items()):
if not hasattr(_FAKE_LOGRECORD, key):
# handle attribute/field name collisions:
# logrecod attrs should not limit or take
Expand Down
12 changes: 9 additions & 3 deletions airbrake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import traceback
import types
import sys

if sys.version_info < (3,):
#Py2 legacy fix
type_of_type = types.TypeType
else:
type_of_type = type

class CheckableQueue(Queue):

Expand Down Expand Up @@ -42,9 +48,9 @@ def is_exc_info_tuple(exc_info):
"""
try:
errtype, value, tback = exc_info
if all(map(lambda x: x is None, exc_info)):
if all([x is None for x in exc_info]):
return True
elif all((isinstance(errtype, types.TypeType),
elif all((isinstance(errtype, type_of_type),
isinstance(value, Exception),
isinstance(tback, types.TracebackType))):
return True
Expand Down Expand Up @@ -92,6 +98,6 @@ def pytb_lastline(excinfo=None):
# strip whitespace, Falsy values,
# and the string 'None', sometimes returned by the traceback module
lines = [line.strip() for line in lines if line]
lines = filter(lambda line: str(line).lower() != 'none', lines)
lines = [line for line in lines if str(line).lower() != 'none']
if lines:
return lines[-1]

0 comments on commit 4d25174

Please sign in to comment.