Skip to content
Closed
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
15 changes: 15 additions & 0 deletions src/sentry/interfaces/stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
(\$\$[\w_]+?CGLIB\$\$)[a-fA-F0-9]+(_[0-9]+)?
''', re.X)

# React-Native:
# file:///var/containers/Bundle/Application/{DEVICE_ID}/HelloWorld.app/main.jsbundle
# Electron:
# file:///x/yy/zzz/Electron.app/Contents/app.asar/file1.js
_js_native_path_re = re.compile(r'^(file\:\/\/)?/.*\/[^\.\/]+(\.app|CodePush|\.app/Contents/Resources/app(\.asar)?/|/resources/app(\.asar)?/)\/')


def trim_package(pkg):
if not pkg:
Expand Down Expand Up @@ -219,6 +225,11 @@ def handle_nan(value):
return value


def strip_js_native_components(value):
# we maintain the leading prefix for compat
return _js_native_path_re.sub('/', value)


class Frame(Interface):
@classmethod
def to_python(cls, data):
Expand All @@ -234,6 +245,10 @@ def to_python(cls, data):
if v is not None and not isinstance(v, six.string_types):
raise InterfaceValidationError("Invalid value for '%s'" % name)

# JS sdk only sends filename
if filename and filename.startswith('file://'):
filename = strip_js_native_components(filename)

# absolute path takes priority over filename
# (in the end both will get set)
if not abs_path:
Expand Down
40 changes: 40 additions & 0 deletions tests/sentry/interfaces/test_stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,46 @@ def test_ignores_results_with_empty_path(self):
assert frame.filename == 'http://foo.com'
assert frame.abs_path == frame.filename

def test_normalizes_react_native_filename(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'file:///var/containers/Bundle/Application/06C10E06-2ABE-41A3-B7F2-3B7452C057B1/HelloWorld.app/main.jsbundle',
}]))
frame = interface.frames[0]
assert frame.filename == '/main.jsbundle'

def test_normalizes_electron_mac_asar_filename(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'file:///x/yy/zzz/Electron.app/Contents/app.asar/file1.js',
}]))
frame = interface.frames[0]
assert frame.filename == '/file1.js'

def test_normalizes_electron_mac_filename(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'file:///x/yy/zzz/Electron.app/Contents/app/file1.js',
}]))
frame = interface.frames[0]
assert frame.filename == '/file1.js'

def test_normalizes_electron_windows_filename(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'file:///x/yy/zzz/Electron/resources/app/file1.js',
}]))
frame = interface.frames[0]
assert frame.filename == '/file1.js'

def test_normalizes_electron_windows_asar_filename(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'file:///x/yy/zzz/Electron/resources/app.asar/file1.js',
}]))
frame = interface.frames[0]
assert frame.filename == '/file1.js'

def test_serialize_returns_frames(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
Expand Down