Fix bug in parseHermesStack.js

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
This commit is contained in:
Martin Sherburn
2021-06-14 02:57:37 -07:00
committed by Facebook GitHub Bot
parent e24b55ef4f
commit e539e7d0be
3 changed files with 41 additions and 1 deletions
@@ -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",
}
`;
@@ -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(
+1 -1
View File
@@ -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