diff --git a/src/stack-trace-parser.js b/src/stack-trace-parser.js index 48a5176..e50e797 100644 --- a/src/stack-trace-parser.js +++ b/src/stack-trace-parser.js @@ -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); @@ -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); diff --git a/test/fixtures/captured-errors.js b/test/fixtures/captured-errors.js index 1842706..8edb3d1 100644 --- a/test/fixtures/captured-errors.js +++ b/test/fixtures/captured-errors.js @@ -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]', + }, }; diff --git a/test/stack-trace-parser.spec.js b/test/stack-trace-parser.spec.js index 8510593..a537150 100644 --- a/test/stack-trace-parser.spec.js +++ b/test/stack-trace-parser.spec.js @@ -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: '', + 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: '', + 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'