Skip to content

Commit

Permalink
Gracefully handle invalid f_locals
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jan 17, 2012
1 parent ac8c044 commit a610ebf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.2

* Gracefully handle invalid f_locals.

1.0.1

* All datetimes are assumed to be utcnow() as of Sentry 2.0.0-RC5
Expand Down
16 changes: 12 additions & 4 deletions raven/utils/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def iter_traceback_frames(tb):
while tb:
# support for __traceback_hide__ which is used by a few libraries
# to hide internal frames.
if not tb.tb_frame.f_locals.get('__traceback_hide__'):
f_locals = tb.tb_frame.f_locals
if not (isinstance(f_locals, dict) and f_locals.get('__traceback_hide__')):
yield tb.tb_frame
tb = tb.tb_next

Expand All @@ -109,7 +110,8 @@ def iter_stack_frames(frames=None):
if not frames:
frames = inspect.stack()[1:]
for frame in (f[0] for f in frames):
if frame.f_locals.get('__traceback_hide__'):
f_locals = frame.f_locals
if (isinstance(f_locals, dict) or f_locals.get('__traceback_hide__')):
continue
yield frame

Expand All @@ -118,7 +120,8 @@ def get_stack_info(frames):
results = []
for frame in frames:
# Support hidden frames
if frame.f_locals.get('__traceback_hide__'):
f_locals = frame.f_locals
if (isinstance(f_locals, dict) or f_locals.get('__traceback_hide__')):
continue

abs_path = frame.f_code.co_filename
Expand All @@ -137,14 +140,19 @@ def get_stack_info(frames):
filename = abs_path

if context_line:
f_locals = frame.f_locals
if not isinstance(f_locals, dict):
# XXX: Genshi (and maybe others) have broken implementations of
# f_locals that are not actually dictionaries
f_locals = '<invalid local scope>'
results.append({
'abs_path': abs_path,
'filename': filename or abs_path,
'module': module_name,
'function': function,
'lineno': lineno + 1,
# TODO: vars need to be references
'vars': transform(frame.f_locals),
'vars': transform(f_locals),
'pre_context': pre_context,
'context_line': context_line,
'post_context': post_context,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name='raven2',
version='1.0.1',
version='1.0.2',
author='David Cramer',
author_email='[email protected]',
url='http://github.com/dcramer/raven',
Expand Down

0 comments on commit a610ebf

Please sign in to comment.