Skip to content

Commit 9bbe736

Browse files
Peter Ammonfacebook-github-bot
authored andcommitted
Teach JS stack-parsing regex about alternative formats
Reviewed By: adamjernst Differential Revision: D7706535 fbshipit-source-id: 83cc2defbcad3faa6bdbf4a5b2072b9c023e1c04
1 parent fc694fe commit 9bbe736

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

React/Base/RCTJSStackFrame.m

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,40 @@
1010
#import "RCTLog.h"
1111
#import "RCTUtils.h"
1212

13+
/**
14+
* The RegEx used to parse Error.stack.
15+
*
16+
* JavaScriptCore has the following format:
17+
*
18+
* Exception: Error: argh
19+
* func1@/path/to/file.js:2:18
20+
* func2@/path/to/file.js:6:8
21+
* eval@[native code]
22+
* global code@/path/to/file.js:13:5
23+
*
24+
* Another supported format:
25+
*
26+
* Error: argh
27+
* at func1 (/path/to/file.js:2:18)
28+
* at func2 (/path/to/file.js:6:8)
29+
* at eval (native)
30+
* at global (/path/to/file.js:13:5)
31+
*/
1332
static NSRegularExpression *RCTJSStackFrameRegex()
1433
{
1534
static dispatch_once_t onceToken;
1635
static NSRegularExpression *_regex;
1736
dispatch_once(&onceToken, ^{
37+
NSString *pattern =
38+
@"\\s*(?:at)?\\s*" // Skip leading "at" and whitespace, noncapturing
39+
@"(.+?)" // Capture the function name (group 1)
40+
@"\\s*[@(]" // Skip whitespace, then @ or (
41+
@"(.*):" // Capture the file name (group 2), then colon
42+
@"(\\d+):(\\d+)" // Line and column number (groups 3 and 4)
43+
@"\\)?$" // Optional closing paren and EOL
44+
;
1845
NSError *regexError;
19-
_regex = [NSRegularExpression regularExpressionWithPattern:@"^(?:([^@]+)@)?(.*):(\\d+):(\\d+)$" options:0 error:&regexError];
46+
_regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&regexError];
2047
if (regexError) {
2148
RCTLogError(@"Failed to build regex: %@", [regexError localizedDescription]);
2249
}

0 commit comments

Comments
 (0)