Skip to content

Commit

Permalink
RN: Fix Symbolicate Logspew for /debuggerWorker.js
Browse files Browse the repository at this point in the history
Summary:
When remote debugging is enabled, stack traces start at `/debuggerWorker.js`. Since this is not a valid bundle URL, the packager fails to decipher it to find its sourcemap.

This changes the packager to skip the `/debuggerWorker.js` stack frame if one exists.

Reviewed By: frantic

Differential Revision: D3418341

fbshipit-source-id: 7434aa45dea7d120d9d77c060101dd9403989d0c
  • Loading branch information
yungsters authored and Facebook Github Bot 9 committed Jun 10, 2016
1 parent 0d572e4 commit 5e73c07
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
24 changes: 23 additions & 1 deletion packager/react-packager/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('processRequest', () => {
requestHandler,
'index.ios.includeRequire.bundle'
).then(response => {
expect(response.body).toEqual('this is the source')
expect(response.body).toEqual('this is the source');
expect(Bundler.prototype.bundle).toBeCalledWith({
entryFile: 'index.ios.js',
inlineSourceMap: false,
Expand Down Expand Up @@ -429,6 +429,28 @@ describe('processRequest', () => {
});
});
});

pit('ignores `/debuggerWorker.js` stack frames', () => {
const body = JSON.stringify({stack: [{
file: 'http://localhost:8081/debuggerWorker.js',
lineNumber: 123,
column: 456,
}]});

return makeRequest(
requestHandler,
'/symbolicate',
{ rawBody: body }
).then(response => {
expect(JSON.parse(response.body)).toEqual({
stack: [{
file: 'http://localhost:8081/debuggerWorker.js',
lineNumber: 123,
column: 456,
}]
});
});
});
});

describe('/symbolicate handles errors', () => {
Expand Down
29 changes: 21 additions & 8 deletions packager/react-packager/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Server {
e => {
res.writeHead(500);
res.end('Internal Error');
console.log(e.stack);
console.log(e.stack); // eslint-disable-line no-console-disallow
}
);
} else if (parts[1] === 'graph'){
Expand Down Expand Up @@ -491,24 +491,37 @@ class Server {

// In case of multiple bundles / HMR, some stack frames can have
// different URLs from others
const urls = stack.map(frame => frame.file);
const uniqueUrls = urls.filter((elem, idx) => urls.indexOf(elem) === idx);
const urlIndexes = {};
const uniqueUrls = [];
stack.forEach(frame => {
const sourceUrl = frame.file;
// Skip `/debuggerWorker.js` which drives remote debugging because it
// does not need to symbolication.
if (!urlIndexes.hasOwnProperty(sourceUrl) &&
!sourceUrl.endsWith('/debuggerWorker.js')) {
urlIndexes[sourceUrl] = uniqueUrls.length;
uniqueUrls.push(sourceUrl);
}
});

const sourceMaps = uniqueUrls.map(sourceUrl => this._sourceMapForURL(sourceUrl));
const sourceMaps = uniqueUrls.map(
sourceUrl => this._sourceMapForURL(sourceUrl)
);
return Promise.all(sourceMaps).then(consumers => {
return stack.map(frame => {
const idx = uniqueUrls.indexOf(frame.file);
const sourceUrl = frame.file;
if (!urlIndexes.hasOwnProperty(sourceUrl)) {
return frame;
}
const idx = urlIndexes[sourceUrl];
const consumer = consumers[idx];

const original = consumer.originalPositionFor({
line: frame.lineNumber,
column: frame.column,
});

if (!original) {
return frame;
}

return Object.assign({}, frame, {
file: original.source,
lineNumber: original.line,
Expand Down

0 comments on commit 5e73c07

Please sign in to comment.