Skip to content

Normalize RN frames in stackfrace interface (synthetic trace) (fixes #776) #778

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 2 commits into from
Nov 22, 2016
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