From 94975209637fb233a25e04e7b691ccc0cb2e73c1 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 10 Jun 2016 12:23:04 -0700 Subject: [PATCH] RN: Fix Symbolicate Logspew for `/debuggerWorker.js` 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 --- .../src/Server/__tests__/Server-test.js | 24 ++++++++++++++- react-packager/src/Server/index.js | 29 ++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index 9d5ec47a..d8d2e96d 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -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, @@ -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', () => { diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index 10258d4f..f040f771 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -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'){ @@ -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,