Skip to content
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this comment about data.exception guaranteeing other keys to be before this var decl; in its current position it doesn't obviously apply to data.exception.values[0], which made me wonder if that was a safe access until I looked at the original where it did obviously apply.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

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