Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def frame_from_traceback(tb, with_locals=True):

rv = {
"filename": abs_path and os.path.basename(abs_path) or None,
"abs_path": abs_path,
"abs_path": os.path.abspath(abs_path),
"function": function or "<unknown>",
"module": module,
"lineno": tb.tb_lineno,
Expand Down
25 changes: 24 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import sys
import os

from hypothesis import given, assume
import hypothesis.strategies as st

from sentry_sdk.utils import safe_repr
from sentry_sdk.utils import safe_repr, exceptions_from_error_tuple
from sentry_sdk._compat import text_type

any_string = st.one_of(st.binary(), st.text())
Expand All @@ -23,3 +26,23 @@ def test_safe_repr_never_leaves_escapes_in(x):
r = safe_repr(x)
assert isinstance(r, text_type)
assert u"\\u" not in r and u"\\x" not in r


def test_abs_path():
"""Check if abs_path is actually an absolute path. This can happen either
with eval/exec like here, or when the file in the frame is relative to
__main__"""

code = compile("1/0", "test.py", "exec")
try:
exec(code, {})
except Exception:
exceptions = exceptions_from_error_tuple(sys.exc_info())

exception, = exceptions
frames = exception["stacktrace"]["frames"]
assert len(frames) == 2

for frame in frames:
assert os.path.abspath(frame["abs_path"]) == frame["abs_path"]
assert os.path.basename(frame["filename"]) == frame["filename"]