Skip to content

Commit

Permalink
Ensure @-less lines will be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
Calamari committed May 5, 2019
1 parent 708c96d commit c91463f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/stack-trace-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function parse(stackString) {
parseChrome(line) ||
parseWinjs(line) ||
parseGecko(line) ||
parseJSC(line) ||
parseNode(line);
parseNode(line) ||
parseJSC(line);

if (parseResult) {
stack.push(parseResult);
Expand Down Expand Up @@ -100,7 +100,7 @@ function parseGecko(line) {
};
}

const javaScriptCoreRe = /^(?:\s*([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i
const javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;

function parseJSC(line) {
const parts = javaScriptCoreRe.exec(line);
Expand Down
21 changes: 19 additions & 2 deletions test/fixtures/captured-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ export default {
_depRunCallbacks@/home/test/project/node_modules/dep/index.js:77:45
tryCallTwo@/home/test/project/node_modules/react-native/node_modules/promise/lib/core.js:45:5
doResolve@/home/test/project/node_modules/react-native/node_modules/promise/lib/core.js:200:13
`
}
`,
},

IOS_REACT_NATIVE_2: {
message:
'Error: from issue https://github.com/facebook/react-native/issues/24382#issuecomment-489404970',
stack:
's@33.js:1:531\n' +
'b@1959.js:1:1469\n' +
'onSocketClose@2932.js:1:727\n' +
'value@81.js:1:1505\n' +
'102.js:1:2956\n' +
'value@89.js:1:1247\n' +
'value@42.js:1:3311\n' +
'42.js:1:822\n' +
'value@42.js:1:2565\n' +
'value@42.js:1:794\n' +
'value@[native code]',
},
};
87 changes: 87 additions & 0 deletions test/stack-trace-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,93 @@ describe('stackTraceParser', () => {
]);
});

it('parses an error in react native', () => {
const stackFrames = stackTraceParser.parse(
CapturedExceptions.IOS_REACT_NATIVE_2.stack
);

expect(stackFrames.length).to.be(11);
expect(stackFrames).to.eql([
{
file: '33.js',
methodName: 's',
arguments: [],
lineNumber: 1,
column: 531,
},
{
file: '1959.js',
methodName: 'b',
arguments: [],
lineNumber: 1,
column: 1469,
},
{
file: '2932.js',
methodName: 'onSocketClose',
arguments: [],
lineNumber: 1,
column: 727,
},
{
file: '81.js',
methodName: 'value',
arguments: [],
lineNumber: 1,
column: 1505,
},
{
file: '102.js',
methodName: '<unknown>',
arguments: [],
lineNumber: 1,
column: 2956,
},
{
file: '89.js',
methodName: 'value',
arguments: [],
lineNumber: 1,
column: 1247,
},
{
file: '42.js',
methodName: 'value',
arguments: [],
lineNumber: 1,
column: 3311,
},
{
file: '42.js',
methodName: '<unknown>',
arguments: [],
lineNumber: 1,
column: 822,
},
{
file: '42.js',
methodName: 'value',
arguments: [],
lineNumber: 1,
column: 2565,
},
{
file: '42.js',
methodName: 'value',
arguments: [],
lineNumber: 1,
column: 794,
},
{
file: '[native code]',
methodName: 'value',
arguments: [],
lineNumber: null,
column: null,
},
]);
});

it('parses very simple JavaScriptCore errors', () => {
const stackFrames = stackTraceParser.parse(
'global code@stack_traces/test:83:55'
Expand Down

0 comments on commit c91463f

Please sign in to comment.