Skip to content

Commit

Permalink
Fix bug in parseHermesStack.js
Browse files Browse the repository at this point in the history
Summary:
If function name is an empty string then it would fail to parse the line. And not only that, it would cause the entire stack to be lost. This fixes the issue by replacing `.+?` with `.*?`.

For example this line fails to parse:
```
    at global (:2:4)
```

Changelog:
[General][Fixed] - Fixed bug parsing hermes call stacks when the file name is empty

Reviewed By: yungsters

Differential Revision: D29063192

fbshipit-source-id: 604e457af51f852fe547e6424283631ae148897d
  • Loading branch information
MartinSherburn authored and facebook-github-bot committed Jun 14, 2021
1 parent e24b55e commit e539e7d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,31 @@ Object {
"message": "TypeError: undefined is not a function",
}
`;

exports[`parseHermesStack tolerate empty filename 1`] = `
Object {
"entries": Array [
Object {
"functionName": "global",
"location": Object {
"column1Based": 9,
"line1Based": 1,
"sourceUrl": "unknown",
"type": "SOURCE",
},
"type": "FRAME",
},
Object {
"functionName": "foo$bar",
"location": Object {
"column1Based": 1234,
"line1Based": 10,
"sourceUrl": "",
"type": "SOURCE",
},
"type": "FRAME",
},
],
"message": "TypeError: undefined is not a function",
}
`;
12 changes: 12 additions & 0 deletions Libraries/Core/Devtools/__tests__/parseHermesStack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ describe('parseHermesStack', () => {
).toMatchSnapshot();
});

test('tolerate empty filename', () => {
expect(
parseHermesStack(
[
'TypeError: undefined is not a function',
' at global (unknown:1:9)',
' at foo$bar (:10:1234)',
].join('\n'),
),
).toMatchSnapshot();
});

test('skipped frames', () => {
expect(
parseHermesStack(
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/Devtools/parseHermesStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type HermesParsedStack = {|
// 4. source URL (filename)
// 5. line number (1 based)
// 6. column number (1 based) or virtual offset (0 based)
const RE_FRAME = /^ {4}at (.+?)(?: \((native)\)?| \((address at )?(.+?):(\d+):(\d+)\))$/;
const RE_FRAME = /^ {4}at (.+?)(?: \((native)\)?| \((address at )?(.*?):(\d+):(\d+)\))$/;

// Capturing groups:
// 1. count of skipped frames
Expand Down

0 comments on commit e539e7d

Please sign in to comment.