@@ -82,28 +82,38 @@ class StackFrame {
82
82
.toList ();
83
83
}
84
84
85
- static StackFrame ? _parseWebFrame (String line) {
85
+ /// Parses a single [StackFrame] from a line of a [StackTrace] .
86
+ ///
87
+ /// Returns null if format is not as expected.
88
+ static StackFrame ? _tryParseWebFrame (String line) {
86
89
if (kDebugMode) {
87
- return _parseWebDebugFrame (line);
90
+ return _tryParseWebDebugFrame (line);
88
91
} else {
89
- return _parseWebNonDebugFrame (line);
92
+ return _tryParseWebNonDebugFrame (line);
90
93
}
91
94
}
92
95
93
- static StackFrame _parseWebDebugFrame (String line) {
96
+ /// Parses a single [StackFrame] from a line of a [StackTrace] .
97
+ ///
98
+ /// Returns null if format is not as expected.
99
+ static StackFrame ? _tryParseWebDebugFrame (String line) {
94
100
// This RegExp is only partially correct for flutter run/test differences.
95
101
// https://github.com/flutter/flutter/issues/52685
96
102
final bool hasPackage = line.startsWith ('package' );
97
103
final RegExp parser = hasPackage
98
104
? RegExp (r'^(package.+) (\d+):(\d+)\s+(.+)$' )
99
105
: RegExp (r'^(.+) (\d+):(\d+)\s+(.+)$' );
100
- Match ? match = parser.firstMatch (line);
101
- assert (match != null , 'Expected $line to match $parser .' );
102
- match = match! ;
106
+
107
+ final Match ? match = parser.firstMatch (line);
108
+
109
+ if (match == null ) {
110
+ return null ;
111
+ }
103
112
104
113
String package = '<unknown>' ;
105
114
String packageScheme = '<unknown>' ;
106
115
String packagePath = '<unknown>' ;
116
+
107
117
if (hasPackage) {
108
118
packageScheme = 'package' ;
109
119
final Uri packageUri = Uri .parse (match.group (1 )! );
@@ -132,7 +142,7 @@ class StackFrame {
132
142
133
143
// Parses `line` as a stack frame in profile and release Web builds. If not
134
144
// recognized as a stack frame, returns null.
135
- static StackFrame ? _parseWebNonDebugFrame (String line) {
145
+ static StackFrame ? _tryParseWebNonDebugFrame (String line) {
136
146
final Match ? match = _webNonDebugFramePattern.firstMatch (line);
137
147
if (match == null ) {
138
148
// On the Web in non-debug builds the stack trace includes the exception
@@ -169,6 +179,8 @@ class StackFrame {
169
179
}
170
180
171
181
/// Parses a single [StackFrame] from a single line of a [StackTrace] .
182
+ ///
183
+ /// Returns null if format is not as expected.
172
184
static StackFrame ? fromStackTraceLine (String line) {
173
185
if (line == '<asynchronous suspension>' ) {
174
186
return asynchronousSuspension;
@@ -185,7 +197,7 @@ class StackFrame {
185
197
186
198
// Web frames.
187
199
if (! line.startsWith ('#' )) {
188
- return _parseWebFrame (line);
200
+ return _tryParseWebFrame (line);
189
201
}
190
202
191
203
final RegExp parser = RegExp (r'^#(\d+) +(.+) \((.+?):?(\d+){0,1}:?(\d+){0,1}\)$' );
0 commit comments