Skip to content

Commit

Permalink
Use absolute file path when symbolicating HBC bundles
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

When enabling Metro with bytecode for apps like Twilight, we're seeing these type of error:
```
Error: ENOENT: no such file or directory, open 'RKJSModules/vendor/react/cjs/React-dev.js'
    at Object.openSync (fs.js:457:3)
    at Object.readFileSync (fs.js:359:35)
    at getCodeFrame (/Users/keo/Library/Caches/dotslash/obj/everstore/f7/GCF5agem2GP1NT0DACsCkMSaYsFCblMqAAAA/extract/tar.gz/metro/src/Server.js:1013:401)
    at Server._symbolicate (/Users/keo/Library/Caches/dotslash/obj/everstore/f7/GCF5agem2GP1NT0DACsCkMSaYsFCblMqAAAA/extract/tar.gz/metro/src/Server.js:1062:20)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Server._processRequest (/Users/keo/Library/Caches/dotslash/obj/everstore/f7/GCF5agem2GP1NT0DACsCkMSaYsFCblMqAAAA/extract/tar.gz/metro/src/Server.js:993:408)
```

This diff ensures we resolve the file to an absolute path and surrounds the `readFileSync` call with a try/catch to make sure we don't hit these errors.

Reviewed By: cpojer

Differential Revision: D25262626

fbshipit-source-id: 5d53e3ccd1942d44beb3873bf3450e7668b0dc29
  • Loading branch information
Keion Anvaripour authored and facebook-github-bot committed Dec 17, 2020
1 parent cd04093 commit 8cf2434
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/metro/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,25 +988,30 @@ class Server {
const getCodeFrame = (urls, symbolicatedStack) => {
for (let i = 0; i < symbolicatedStack.length; i++) {
const {collapse, column, file, lineNumber} = symbolicatedStack[i];
if (collapse || lineNumber == null || urls.has(file)) {
const entryPoint = path.resolve(this._config.projectRoot, file);
if (collapse || lineNumber == null || urls.has(entryPoint)) {
continue;
}

return {
content: codeFrameColumns(
fs.readFileSync(file, 'utf8'),
{
// Metro returns 0 based columns but codeFrameColumns expects 1-based columns
start: {column: column + 1, line: lineNumber},
try {
return {
content: codeFrameColumns(
fs.readFileSync(entryPoint, 'utf8'),
{
// Metro returns 0 based columns but codeFrameColumns expects 1-based columns
start: {column: column + 1, line: lineNumber},
},
{forceColor: true},
),
location: {
row: lineNumber,
column,
},
{forceColor: true},
),
location: {
row: lineNumber,
column,
},
fileName: file,
};
fileName: file,
};
} catch (error) {
console.error(error);
}
}

return null;
Expand Down

0 comments on commit 8cf2434

Please sign in to comment.