fix stack frame parser (#69253)

This commit is contained in:
Yegor 2020-10-28 19:27:04 -07:00 committed by GitHub
parent e5c4c4b27a
commit 46b1b67797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -211,7 +211,9 @@ class StackFrame {
String className = '';
String method = match.group(2)!.replaceAll('.<anonymous closure>', '');
if (method.startsWith('new')) {
className = method.split(' ')[1];
final List<String> methodParts = method.split(' ');
// Sometimes a web frame will only read "new" and have no class name.
className = methodParts.length > 1 ? method.split(' ')[1] : '<unknown>';
method = '';
if (className.contains('.')) {
final List<String> parts = className.split('.');

View file

@ -81,6 +81,24 @@ void main() {
expect('$e', contains('Got a stack frame from package:stack_trace'));
}
});
test('Can parse web constructor invocation with unknown class name', () {
const String stackTraceLine = '#32 new (http://localhost:42191/dart-sdk/lib/async/stream_controller.dart:880:9)';
expect(
StackFrame.fromStackTraceLine(stackTraceLine),
const StackFrame(
number: 32,
className: '<unknown>',
method: '',
packageScheme: 'http',
package: '<unknown>',
packagePath: 'dart-sdk/lib/async/stream_controller.dart',
line: 880,
column: 9,
source: stackTraceLine,
),
);
});
}
const String stackString = '''