@@ -82,28 +82,38 @@ class StackFrame {
8282 .toList ();
8383 }
8484
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) {
8689 if (kDebugMode) {
87- return _parseWebDebugFrame (line);
90+ return _tryParseWebDebugFrame (line);
8891 } else {
89- return _parseWebNonDebugFrame (line);
92+ return _tryParseWebNonDebugFrame (line);
9093 }
9194 }
9295
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) {
94100 // This RegExp is only partially correct for flutter run/test differences.
95101 // https://github.com/flutter/flutter/issues/52685
96102 final bool hasPackage = line.startsWith ('package' );
97103 final RegExp parser = hasPackage
98104 ? RegExp (r'^(package.+) (\d+):(\d+)\s+(.+)$' )
99105 : 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+ }
103112
104113 String package = '<unknown>' ;
105114 String packageScheme = '<unknown>' ;
106115 String packagePath = '<unknown>' ;
116+
107117 if (hasPackage) {
108118 packageScheme = 'package' ;
109119 final Uri packageUri = Uri .parse (match.group (1 )! );
@@ -132,7 +142,7 @@ class StackFrame {
132142
133143 // Parses `line` as a stack frame in profile and release Web builds. If not
134144 // recognized as a stack frame, returns null.
135- static StackFrame ? _parseWebNonDebugFrame (String line) {
145+ static StackFrame ? _tryParseWebNonDebugFrame (String line) {
136146 final Match ? match = _webNonDebugFramePattern.firstMatch (line);
137147 if (match == null ) {
138148 // On the Web in non-debug builds the stack trace includes the exception
@@ -169,6 +179,8 @@ class StackFrame {
169179 }
170180
171181 /// Parses a single [StackFrame] from a single line of a [StackTrace] .
182+ ///
183+ /// Returns null if format is not as expected.
172184 static StackFrame ? fromStackTraceLine (String line) {
173185 if (line == '<asynchronous suspension>' ) {
174186 return asynchronousSuspension;
@@ -185,7 +197,7 @@ class StackFrame {
185197
186198 // Web frames.
187199 if (! line.startsWith ('#' )) {
188- return _parseWebFrame (line);
200+ return _tryParseWebFrame (line);
189201 }
190202
191203 final RegExp parser = RegExp (r'^#(\d+) +(.+) \((.+?):?(\d+){0,1}:?(\d+){0,1}\)$' );
0 commit comments