Ensure user-thrown errors have ErrorSummary nodes (#36857)
This commit is contained in:
parent
7c27142e58
commit
aa9ca8fc5e
@ -411,7 +411,7 @@ class FlutterErrorDetails extends Diagnosticable {
|
|||||||
String message = exceptionAsString();
|
String message = exceptionAsString();
|
||||||
if (message.startsWith(prefix))
|
if (message.startsWith(prefix))
|
||||||
message = message.substring(prefix.length);
|
message = message.substring(prefix.length);
|
||||||
properties.add(ErrorDescription('$message'));
|
properties.add(ErrorSummary('$message'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,4 +328,28 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('User-thrown exceptions have ErrorSummary properties', () {
|
||||||
|
{
|
||||||
|
DiagnosticsNode node;
|
||||||
|
try {
|
||||||
|
throw 'User thrown string';
|
||||||
|
} catch (e) {
|
||||||
|
node = FlutterErrorDetails(exception: e).toDiagnosticsNode();
|
||||||
|
}
|
||||||
|
final ErrorSummary summary = node.getProperties().whereType<ErrorSummary>().single;
|
||||||
|
expect(summary.value, equals(<String>['User thrown string']));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
DiagnosticsNode node;
|
||||||
|
try {
|
||||||
|
throw ArgumentError.notNull('myArgument');
|
||||||
|
} catch (e) {
|
||||||
|
node = FlutterErrorDetails(exception: e).toDiagnosticsNode();
|
||||||
|
}
|
||||||
|
final ErrorSummary summary = node.getProperties().whereType<ErrorSummary>().single;
|
||||||
|
expect(summary.value, equals(<String>['Invalid argument(s) (myArgument): Must not be null']));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user