Skip to content

Commit

Permalink
Normalize RN frames in stackfrace interface (synthetic trace) (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar authored Nov 22, 2016
1 parent 9a58ae0 commit 6fa89f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 5 additions & 3 deletions plugins/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
34 changes: 33 additions & 1 deletion test/plugins/react-native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 6fa89f2

Please sign in to comment.