Skip to content

Commit

Permalink
Protect from scenarios where all frames should be ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Dec 4, 2015
1 parent a046d44 commit 7003f6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/structlog/_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def _find_first_app_frame_and_name(additional_ignores=None):
f = sys._getframe()
name = f.f_globals.get("__name__") or "?"
while any(name.startswith(i) for i in ignores):
if f.f_back is None:
break
f = f.f_back
name = f.f_globals.get("__name__") or "?"
return f, name
Expand Down
9 changes: 9 additions & 0 deletions tests/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def test_tolerates_name_explicitly_None_manyframe(self, monkeypatch):
f, n = _find_first_app_frame_and_name()
assert ((f1, "?") == (f, n))

def test_tolerates_f_back_is_None(self, monkeypatch):
"""
Use ``?`` if all frames are in ignored frames.
"""
f1 = stub(f_globals={'__name__': 'hello_world'}, f_back=None)
monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f1)
f, n = _find_first_app_frame_and_name()
assert ((f1, "?") == (f, n))


@pytest.fixture
def exc_info():
Expand Down

0 comments on commit 7003f6c

Please sign in to comment.