Skip to content

Commit 7dbc805

Browse files
LaguanaFacebook Github Bot 5
authored andcommitted
Fix symbolication outside of chrome debugging
Summary: When debugging in VScode or nucleide using a nodejs environment rather than chrome, the JS sources are made to appear as if they exist on disk, rather than coming from a `http://` url. Prior to this change the packager would see these file paths and not know how to handle them. Since all the application JS will be part of a bundle file, we can switch out the path to the bundle on the filesystem with paths to the bundle served by the packager, and things will work just as though it was debugging in chrome. We stop the replacement once we reach an internal module (`vm.js` in the case of both nucleide and VSCode) since that is the point when the execution switches from inside the app to the surrounding debugging environment. I've verified that this fixes redbox stack trace symbolication in VSCode, and from my understanding of nucleide's debugging environment it should also work there without requiring any changes. Closes facebook#9906 Differential Revision: D3887166 Pulled By: davidaurelio fbshipit-source-id: e3a6704f30e0fd045ad836bba51f6e20d9854c30
1 parent 38c5621 commit 7dbc805

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Libraries/JavaScriptAppEngine/Initialization/symbolicateStackTrace.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const {fetch} = require('fetch');
1515
const getDevServer = require('getDevServer');
16+
const {SourceCode} = require('NativeModules');
1617

1718
import type {StackFrame} from 'parseErrorStack';
1819

@@ -21,6 +22,19 @@ async function symbolicateStackTrace(stack: Array<StackFrame>): Promise<Array<St
2122
if (!devServer.bundleLoadedFromServer) {
2223
throw new Error('Bundle was not loaded from the packager');
2324
}
25+
if (SourceCode.scriptURL) {
26+
for (let i = 0; i < stack.length; ++i) {
27+
// If the sources exist on disk rather than appearing to come from the packager,
28+
// replace the location with the packager URL until we reach an internal source
29+
// which does not have a path (no slashes), indicating a switch from within
30+
// the application to a surrounding debugging environment.
31+
if (/^http/.test(stack[i].file) || !/[\\/]/.test(stack[i].file)) {
32+
break;
33+
}
34+
stack[i].file = SourceCode.scriptURL;
35+
}
36+
}
37+
2438
const response = await fetch(devServer.url + 'symbolicate', {
2539
method: 'POST',
2640
body: JSON.stringify({stack}),

0 commit comments

Comments
 (0)