Skip to content

Commit b3551f7

Browse files
committed
Normalize RN frames in stackfrace interface (synthetic trace) (fixes #776)
1 parent 0d80b49 commit b3551f7

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

plugins/react-native.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ reactNativePlugin._normalizeData = function (data, pathStripRe) {
214214
data.culprit = normalizeUrl(data.culprit, pathStripRe);
215215
}
216216

217-
if (data.exception) {
217+
var stacktrace = data.stacktrace || data.exception && data.exception.values[0].stacktrace;
218+
if (stacktrace) {
218219
// if data.exception exists, all of the other keys are guaranteed to exist
219-
data.exception.values[0].stacktrace.frames.forEach(function (frame) {
220+
stacktrace.frames.forEach(function (frame) {
220221
frame.filename = normalizeUrl(frame.filename, pathStripRe);
221222
});
222223
}

test/plugins/react-native.test.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('React Native plugin', function () {
1717
});
1818

1919
describe('_normalizeData()', function () {
20-
it('should normalize culprit and frame filenames/URLs from app', function () {
20+
it('should normalize culprit and frame filenames/URLs from .app directory', function () {
2121
var data = {
2222
project: '2',
2323
logger: 'javascript',
@@ -53,6 +53,38 @@ describe('React Native plugin', function () {
5353
assert.equal(frames[1].filename, '/file2.js');
5454
});
5555

56+
it('should normalize culprit and frame filenames/URLs from stacktrace interface', function () {
57+
var data = {
58+
project: '2',
59+
logger: 'javascript',
60+
platform: 'javascript',
61+
62+
culprit: 'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/app.js',
63+
message: 'Error: crap',
64+
65+
stacktrace: {
66+
frames: [{
67+
filename: 'file:///var/containers/Bundle/Application/ABC/123.app/file1.js',
68+
lineno: 10,
69+
colno: 11,
70+
'function': 'broken'
71+
72+
}, {
73+
filename: 'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/file2.js',
74+
lineno: 12,
75+
colno: 13,
76+
'function': 'lol'
77+
}]
78+
}
79+
};
80+
reactNativePlugin._normalizeData(data);
81+
82+
assert.equal(data.culprit, '/app.js');
83+
var frames = data.stacktrace.frames;
84+
assert.equal(frames[0].filename, '/file1.js');
85+
assert.equal(frames[1].filename, '/file2.js');
86+
});
87+
5688
it('should normalize culprit and frame filenames/URLs from CodePush', function () {
5789
var data = {
5890
project: '2',

0 commit comments

Comments
 (0)