Skip to content

Commit b65087a

Browse files
committed
Fix incorrect behavior in fix_culprit for js.
This was trying to generate_culprit based on the unprocessed data. Instead, we have a real stacktrace object that has been mapped with our sourcemaps and prettied up, so we should extract culprit string out of that instead of the initial raw data.
1 parent 5eb65ea commit b65087a

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/sentry/lang/javascript/processor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ZeroReturnError(Exception):
2525
from sentry import http
2626
from sentry.interfaces.stacktrace import Stacktrace
2727
from sentry.models import EventError, Release, ReleaseFile
28-
from sentry.event_manager import generate_culprit
2928
from sentry.utils.cache import cache
3029
from sentry.utils.hashlib import md5
3130
from sentry.utils.http import is_valid_origin
@@ -462,7 +461,15 @@ def process(self, project, data):
462461
return data
463462

464463
def fix_culprit(self, data, stacktraces):
465-
data['culprit'] = generate_culprit(data)
464+
# This is a bit weird, since the original culprit we get
465+
# will be wrong, so we want to touch it up after we've processed
466+
# a stack trace.
467+
468+
# In this case, we have a list of all stacktraces as a tuple
469+
# (stacktrace as dict, stacktrace class)
470+
# So we need to take the [1] index to get the Stacktrace class,
471+
# then extract the culprit string from that.
472+
data['culprit'] = stacktraces[-1][1].get_culprit_string()
466473

467474
def update_stacktraces(self, stacktraces):
468475
for raw, interface in stacktraces:

tests/sentry/lang/javascript/test_processor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,36 @@ def test_get_stacktraces_returns_exception_interface(self):
216216
result = processor.get_stacktraces(data)
217217
assert len(result) == 1
218218
assert type(result[0][1]) is Stacktrace
219+
220+
def test_get_culprit_is_patched(self):
221+
data = {
222+
'message': 'hello',
223+
'platform': 'javascript',
224+
'sentry.interfaces.Exception': {
225+
'values': [{
226+
'type': 'Error',
227+
'stacktrace': {
228+
'frames': [
229+
{
230+
'abs_path': 'http://example.com/foo.js',
231+
'filename': 'foo.js',
232+
'lineno': 4,
233+
'colno': 0,
234+
'function': 'thing',
235+
},
236+
{
237+
'abs_path': 'http://example.com/bar.js',
238+
'filename': 'bar.js',
239+
'lineno': 1,
240+
'colno': 0,
241+
'function': 'oops',
242+
},
243+
],
244+
},
245+
}],
246+
}
247+
}
248+
249+
processor = SourceProcessor()
250+
result = processor.process(self.project, data)
251+
assert result['culprit'] == 'bar in oops'

0 commit comments

Comments
 (0)