Make FlutterErrorDetails.exception non-nullable as documented (#67364)

This commit is contained in:
Michael Goderbauer
2020-10-05 18:07:02 -07:00
committed by GitHub
parent 1271447bbe
commit 8998167d0f
21 changed files with 46 additions and 47 deletions

View File

@@ -686,7 +686,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
};
final Completer<void> testCompleter = Completer<void>();
final VoidCallback testCompletionHandler = _createTestCompletionHandler(description, testCompleter);
void handleUncaughtError(dynamic exception, StackTrace stack) {
void handleUncaughtError(Object exception, StackTrace stack) {
if (testCompleter.isCompleted) {
// Well this is not a good sign.
// Ideally, once the test has failed we would stop getting errors from the test.
@@ -765,7 +765,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
_parentZone!.run<void>(testCompletionHandler);
}
final ZoneSpecification errorHandlingZoneSpecification = ZoneSpecification(
handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone, dynamic exception, StackTrace stack) {
handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone, Object exception, StackTrace stack) {
handleUncaughtError(exception, stack);
}
);
@@ -1013,7 +1013,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
return realAsyncZone.run<Future<T>>(() {
_pendingAsyncTasks = Completer<void>();
return callback().catchError((dynamic exception, StackTrace stack) {
return callback().catchError((Object exception, StackTrace stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,

View File

@@ -28,7 +28,7 @@ Future<void> main() async {
completer.future.then(
(String value) {},
onError: (dynamic error, StackTrace stack) {
onError: (Object error, StackTrace stack) {
assert(stack is stack_trace.Chain);
FlutterError.reportError(FlutterErrorDetails(
exception: error,

View File

@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
Future<void> main(FutureOr<void> testMain()) async {
reportTestException = (FlutterErrorDetails details, String testDescription) {
expect(details.exception, isA<StateError>());
expect(details.exception.message, 'foo');
expect((details.exception as StateError).message, 'foo');
expect(testDescription, 'custom exception reporter');
};

View File

@@ -737,7 +737,7 @@ void main() {
}, () {});
expect(flutterErrorDetails.exception, isA<AssertionError>());
expect(flutterErrorDetails.exception!.message, 'A Timer is still pending even after the widget tree was disposed.');
expect((flutterErrorDetails.exception as AssertionError).message, 'A Timer is still pending even after the widget tree was disposed.');
});
});
}