Skip to content

Fix android react native release builds stacktrace #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2017
Merged
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
10 changes: 7 additions & 3 deletions plugins/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ var ASYNC_STORAGE_KEY = '--raven-js-global-error-payload--';
* Strip device-specific IDs from React Native file:// paths
*/
function normalizeUrl(url, pathStripRe) {
return url
.replace(/^file\:\/\//, '')
.replace(pathStripRe, '');
if (url.indexOf('/') !== -1) {
return url
.replace(/^file\:\/\//, '')
.replace(pathStripRe, '');
} else {
return '/' + url;
}
}

/**
Expand Down
44 changes: 44 additions & 0 deletions test/vendor/fixtures/captured-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,48 @@ CapturedExceptions.ANDROID_REACT_NATIVE = {

};

CapturedExceptions.ANDROID_REACT_NATIVE_PROD = {
message: 'Error: test',
name: 'Error',
stack: '[email protected]:12:1917\n' +
'[email protected]:12:2336\n' +
'[email protected]:258:1497\n' +
'[native code]\n' +
'[email protected]:252:8508\n' +
'[native code]\n' +
'[email protected]:252:7291\n' +
'[native code]\n' +
'[email protected]:252:4735\n' +
'[native code]\n' +
'[email protected]:79:142\n' +
'[email protected]:79:459\n' +
'[email protected]:79:580\n' +
'[email protected]:95:365\n' +
'[email protected]:95:567\n' +
'[email protected]:146:501\n' +
'[email protected]:146:604\n' +
'forEach@[native code]\n' +
'[email protected]:149:80\n' +
'[email protected]:146:1432\n' +
'[email protected]:157:88\n' +
'[email protected]:157:174\n' +
'index.android.bundle:156:572\n' +
'[email protected]:93:276\n' +
'[email protected]:93:60\n' +
'[email protected]:177:596\n' +
'[email protected]:188:464\n' +
'[email protected]:176:358\n' +
'[email protected]:93:90\n' +
'[email protected]:93:150\n' +
'[email protected]:156:544\n' +
'[email protected]:156:918\n' +
'[email protected]:29:3016\n' +
'index.android.bundle:29:955\n' +
'[email protected]:29:2417\n' +
'[email protected]:29:927\n' +
'[native code]'
};



module.exports = CapturedExceptions;
9 changes: 9 additions & 0 deletions test/vendor/tracekit-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,14 @@ describe('TraceKit', function () {
assert.deepEqual(stackFrames.stack[0], { url: '/home/username/sample-workspace/sampleapp.collect.react/src/components/GpsMonitorScene.js', func: 'render', args: [], line: 78, column: 24 });
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 });
});

it('should parse React Native errors on Android Production', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.ANDROID_REACT_NATIVE_PROD);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 37);
assert.deepEqual(stackFrames.stack[0], { url: 'index.android.bundle', func: 'value', args: [], line: 12, column: 1917 });
assert.deepEqual(stackFrames.stack[35], { url: 'index.android.bundle', func: 'value', args: [], line: 29, column: 927 });
assert.deepEqual(stackFrames.stack[36], { url: '[native code]', func: '?', args: [], line: null, column: null });
});
});
});
2 changes: 1 addition & 1 deletion vendor/TraceKit/tracekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
if (typeof ex.stack === 'undefined' || !ex.stack) return;

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

// Used to additionally parse URL/line/column from eval frames
Expand Down