diff --git a/plugins/react-native.js b/plugins/react-native.js index a33c929bfe0d..546c3e8276d2 100644 --- a/plugins/react-native.js +++ b/plugins/react-native.js @@ -214,9 +214,11 @@ reactNativePlugin._normalizeData = function (data, pathStripRe) { data.culprit = normalizeUrl(data.culprit, pathStripRe); } - if (data.exception) { - // if data.exception exists, all of the other keys are guaranteed to exist - data.exception.values[0].stacktrace.frames.forEach(function (frame) { + // NOTE: if data.exception exists, exception.values and exception.values[0] are + // guaranteed to exist + var stacktrace = data.stacktrace || data.exception && data.exception.values[0].stacktrace; + if (stacktrace) { + stacktrace.frames.forEach(function (frame) { frame.filename = normalizeUrl(frame.filename, pathStripRe); }); } diff --git a/test/plugins/react-native.test.js b/test/plugins/react-native.test.js index 5eea410dc665..48b40e7f301a 100644 --- a/test/plugins/react-native.test.js +++ b/test/plugins/react-native.test.js @@ -17,7 +17,7 @@ describe('React Native plugin', function () { }); describe('_normalizeData()', function () { - it('should normalize culprit and frame filenames/URLs from app', function () { + it('should normalize culprit and frame filenames/URLs from .app directory', function () { var data = { project: '2', logger: 'javascript', @@ -53,6 +53,38 @@ describe('React Native plugin', function () { assert.equal(frames[1].filename, '/file2.js'); }); + it('should normalize culprit and frame filenames/URLs from stacktrace interface', function () { + var data = { + project: '2', + logger: 'javascript', + platform: 'javascript', + + culprit: 'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/app.js', + message: 'Error: crap', + + stacktrace: { + frames: [{ + filename: 'file:///var/containers/Bundle/Application/ABC/123.app/file1.js', + lineno: 10, + colno: 11, + 'function': 'broken' + + }, { + filename: 'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/file2.js', + lineno: 12, + colno: 13, + 'function': 'lol' + }] + } + }; + reactNativePlugin._normalizeData(data); + + assert.equal(data.culprit, '/app.js'); + var frames = data.stacktrace.frames; + assert.equal(frames[0].filename, '/file1.js'); + assert.equal(frames[1].filename, '/file2.js'); + }); + it('should normalize culprit and frame filenames/URLs from CodePush', function () { var data = { project: '2',