Skip to content

Commit 41af72e

Browse files
authored
Merge pull request #985 from getsentry/bugfix/fix-android-react-native-stacktrace
Fix android react native release builds stacktrace
2 parents c3b2d6a + cadda13 commit 41af72e

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

plugins/react-native.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ var ASYNC_STORAGE_KEY = '--raven-js-global-error-payload--';
3333
* Strip device-specific IDs from React Native file:// paths
3434
*/
3535
function normalizeUrl(url, pathStripRe) {
36-
return url
37-
.replace(/^file\:\/\//, '')
38-
.replace(pathStripRe, '');
36+
if (url.indexOf('/') !== -1) {
37+
return url
38+
.replace(/^file\:\/\//, '')
39+
.replace(pathStripRe, '');
40+
} else {
41+
return '/' + url;
42+
}
3943
}
4044

4145
/**

test/vendor/fixtures/captured-errors.js

+44
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,48 @@ CapturedExceptions.ANDROID_REACT_NATIVE = {
400400

401401
};
402402

403+
CapturedExceptions.ANDROID_REACT_NATIVE_PROD = {
404+
message: 'Error: test',
405+
name: 'Error',
406+
stack: '[email protected]:12:1917\n' +
407+
'[email protected]:12:2336\n' +
408+
'[email protected]:258:1497\n' +
409+
'[native code]\n' +
410+
'[email protected]:252:8508\n' +
411+
'[native code]\n' +
412+
'[email protected]:252:7291\n' +
413+
'[native code]\n' +
414+
'[email protected]:252:4735\n' +
415+
'[native code]\n' +
416+
'[email protected]:79:142\n' +
417+
'[email protected]:79:459\n' +
418+
'[email protected]:79:580\n' +
419+
'[email protected]:95:365\n' +
420+
'[email protected]:95:567\n' +
421+
'[email protected]:146:501\n' +
422+
'[email protected]:146:604\n' +
423+
'forEach@[native code]\n' +
424+
'[email protected]:149:80\n' +
425+
'[email protected]:146:1432\n' +
426+
'[email protected]:157:88\n' +
427+
'[email protected]:157:174\n' +
428+
'index.android.bundle:156:572\n' +
429+
'[email protected]:93:276\n' +
430+
'[email protected]:93:60\n' +
431+
'[email protected]:177:596\n' +
432+
'[email protected]:188:464\n' +
433+
'[email protected]:176:358\n' +
434+
'[email protected]:93:90\n' +
435+
'[email protected]:93:150\n' +
436+
'[email protected]:156:544\n' +
437+
'[email protected]:156:918\n' +
438+
'[email protected]:29:3016\n' +
439+
'index.android.bundle:29:955\n' +
440+
'[email protected]:29:2417\n' +
441+
'[email protected]:29:927\n' +
442+
'[native code]'
443+
};
444+
445+
446+
403447
module.exports = CapturedExceptions;

test/vendor/tracekit-parser.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,14 @@ describe('TraceKit', function () {
257257
assert.deepEqual(stackFrames.stack[0], { url: '/home/username/sample-workspace/sampleapp.collect.react/src/components/GpsMonitorScene.js', func: 'render', args: [], line: 78, column: 24 });
258258
assert.deepEqual(stackFrames.stack[7], { url: '/home/username/sample-workspace/sampleapp.collect.react/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeBaseComponent.js', func: 'this', args: [], line: 74, column: 41 });
259259
});
260+
261+
it('should parse React Native errors on Android Production', function () {
262+
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.ANDROID_REACT_NATIVE_PROD);
263+
assert.ok(stackFrames);
264+
assert.deepEqual(stackFrames.stack.length, 37);
265+
assert.deepEqual(stackFrames.stack[0], { url: 'index.android.bundle', func: 'value', args: [], line: 12, column: 1917 });
266+
assert.deepEqual(stackFrames.stack[35], { url: 'index.android.bundle', func: 'value', args: [], line: 29, column: 927 });
267+
assert.deepEqual(stackFrames.stack[36], { url: '[native code]', func: '?', args: [], line: null, column: null });
268+
});
260269
});
261270
});

vendor/TraceKit/tracekit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
370370
if (typeof ex.stack === 'undefined' || !ex.stack) return;
371371

372372
var chrome = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
373-
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?)(?::(\d+))?(?::(\d+))?\s*$/i,
373+
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,
374374
winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
375375

376376
// Used to additionally parse URL/line/column from eval frames

0 commit comments

Comments
 (0)