Reland: [flutter_tool] Where possible, catch only subtypes of Exception (#51567)
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart
index ceeedc1..ad93955 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart
@@ -7,6 +7,7 @@
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/assemble.dart';
+import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
@@ -15,6 +16,7 @@
import '../../src/testbed.dart';
void main() {
+ FlutterCommandRunner.initFlutterRoot();
Cache.disableLocking();
final Testbed testbed = Testbed(overrides: <Type, Generator>{
BuildSystem: () => MockBuildSystem(),
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
index 9a9535e..488ffa2 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
@@ -76,7 +76,7 @@
'--show-test-device',
]);
fail('Expect exception');
- } catch (e) {
+ } on Exception catch (e) {
expect(e.toString(), isNot(contains('--fast-start is not supported with --use-application-binary')));
}
}, overrides: <Type, Generator>{
@@ -102,7 +102,7 @@
'--no-pub',
]);
fail('Expect exception');
- } catch (e) {
+ } on Exception catch (e) {
expect(e, isInstanceOf<ToolExit>());
}
final BufferLogger bufferLogger = globals.logger as BufferLogger;
@@ -127,7 +127,7 @@
'--no-pub',
]);
fail('Expect exception');
- } catch (e) {
+ } on Exception catch (e) {
expect(e, isInstanceOf<ToolExit>());
expect(e.toString(), contains('No pubspec.yaml file found'));
}
@@ -221,8 +221,8 @@
} on ToolExit catch (e) {
// We expect a ToolExit because no devices are attached
expect(e.message, null);
- } catch (e) {
- fail('ToolExit expected');
+ } on Exception catch (e) {
+ fail('ToolExit expected, got $e');
}
verifyInOrder(<void>[
@@ -293,8 +293,8 @@
} on ToolExit catch (e) {
// We expect a ToolExit because app does not start
expect(e.message, null);
- } catch (e) {
- fail('ToolExit expected');
+ } on Exception catch (e) {
+ fail('ToolExit expected, got $e');
}
final List<dynamic> captures = verify(mockUsage.sendCommand(
captureAny,
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/version_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/version_test.dart
index 482c379..972b433 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/version_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/version_test.dart
@@ -163,7 +163,7 @@
try {
await command.getTags();
fail('ToolExit expected');
- } catch(e) {
+ } on Exception catch (e) {
expect(e, isA<ToolExit>());
}
}, overrides: <Type, Generator>{
diff --git a/packages/flutter_tools/test/general.shard/android/android_device_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_test.dart
index 9097626..982550d 100644
--- a/packages/flutter_tools/test/general.shard/android/android_device_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_device_test.dart
@@ -584,7 +584,9 @@
final AndroidDevice device = AndroidDevice('emulator-5555');
expect(await device.emulatorId, isNull);
}, overrides: <Type, Generator>{
- AndroidConsoleSocketFactory: () => (String host, int port) => throw 'Fake socket error',
+ AndroidConsoleSocketFactory: () {
+ return (String host, int port) => throw Exception('Fake socket error');
+ },
ProcessManager: () => mockProcessManager,
});
diff --git a/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart b/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
index b1cfd66..8f12b4e 100644
--- a/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
@@ -80,6 +80,13 @@
when(globals.processManager.runSync(<String>[sdk.sdkManagerPath, '--version'],
environment: argThat(isNotNull, named: 'environment')))
.thenReturn(ProcessResult(1, 0, '26.1.1\n', ''));
+ if (globals.platform.isMacOS) {
+ when(globals.processManager.runSync(
+ <String>['/usr/libexec/java_home'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 0, '', ''));
+ }
expect(sdk.sdkManagerVersion, '26.1.1');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
@@ -112,6 +119,13 @@
when(globals.processManager.runSync(<String>[sdk.sdkManagerPath, '--version'],
environment: argThat(isNotNull, named: 'environment')))
.thenReturn(ProcessResult(1, 1, '26.1.1\n', 'Mystery error'));
+ if (globals.platform.isMacOS) {
+ when(globals.processManager.runSync(
+ <String>['/usr/libexec/java_home'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 0, '', ''));
+ }
expect(sdk.sdkManagerVersion, isNull);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
index e75dde6..515d129 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
@@ -70,26 +70,32 @@
Future<void> buildAndVerifyAssets(
List<String> assets,
List<String> packages,
- String expectedAssetManifest,
- ) async {
+ String expectedAssetManifest, {
+ bool expectExists = true,
+ }) async {
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
for (final String packageName in packages) {
for (final String asset in assets) {
final String entryKey = Uri.encodeFull('packages/$packageName/$asset');
- expect(bundle.entries.containsKey(entryKey), true, reason: 'Cannot find key on bundle: $entryKey');
- expect(
- utf8.decode(await bundle.entries[entryKey].contentsAsBytes()),
- asset,
- );
+ expect(bundle.entries.containsKey(entryKey), expectExists,
+ reason: 'Cannot find key on bundle: $entryKey');
+ if (expectExists) {
+ expect(
+ utf8.decode(await bundle.entries[entryKey].contentsAsBytes()),
+ asset,
+ );
+ }
}
}
- expect(
- utf8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
- expectedAssetManifest,
- );
+ if (expectExists) {
+ expect(
+ utf8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
+ expectedAssetManifest,
+ );
+ }
}
void writeAssets(String path, List<String> assets) {
@@ -660,24 +666,15 @@
assets: assetOnManifest,
);
- try {
- await buildAndVerifyAssets(
- assetOnManifest,
- <String>['test_package'],
- null,
- );
-
- final Function watchdog = () async {
- assert(false, 'Code failed to detect missing directory. Test failed.');
- };
- watchdog();
- } catch (e) {
- // Test successful
- }
+ await buildAndVerifyAssets(
+ assetOnManifest,
+ <String>['test_package'],
+ null,
+ expectExists: false,
+ );
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
-
});
}
diff --git a/packages/flutter_tools/test/general.shard/base/async_guard_test.dart b/packages/flutter_tools/test/general.shard/base/async_guard_test.dart
index f0c46b7..681d7eb 100644
--- a/packages/flutter_tools/test/general.shard/base/async_guard_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/async_guard_test.dart
@@ -197,7 +197,7 @@
);
try {
await f;
- } catch (e) {
+ } on String {
caughtByHandler = true;
}
if (!completer.isCompleted) {
@@ -235,7 +235,7 @@
);
try {
await f;
- } catch (e) {
+ } on String {
caughtByHandler = true;
}
if (!completer.isCompleted) {
@@ -275,7 +275,7 @@
);
try {
await f;
- } catch (e) {
+ } on String {
caughtByHandler = true;
}
if (!completer.isCompleted) {
diff --git a/packages/flutter_tools/test/general.shard/base/fingerprint_test.dart b/packages/flutter_tools/test/general.shard/base/fingerprint_test.dart
index f57c970..cef022c 100644
--- a/packages/flutter_tools/test/general.shard/base/fingerprint_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/fingerprint_test.dart
@@ -249,7 +249,7 @@
globals.fs.file('a.dart').createSync();
expect(
() => Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']),
- throwsArgumentError,
+ throwsException,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
@@ -328,7 +328,7 @@
'properties': <String, String>{},
'files': <String, String>{},
});
- expect(() => Fingerprint.fromJson(jsonString), throwsArgumentError);
+ expect(() => Fingerprint.fromJson(jsonString), throwsException);
}, overrides: <Type, Generator>{
FlutterVersion: () => mockVersion,
});
@@ -338,7 +338,7 @@
'properties': <String, String>{},
'files': <String, String>{},
});
- expect(() => Fingerprint.fromJson(jsonString), throwsArgumentError);
+ expect(() => Fingerprint.fromJson(jsonString), throwsException);
}, overrides: <Type, Generator>{
FlutterVersion: () => mockVersion,
});
diff --git a/packages/flutter_tools/test/general.shard/base/signals_test.dart b/packages/flutter_tools/test/general.shard/base/signals_test.dart
index a3369d6..3c7f9f2 100644
--- a/packages/flutter_tools/test/general.shard/base/signals_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/signals_test.dart
@@ -61,8 +61,9 @@
});
testUsingContext('signal handler error goes on error stream', () async {
+ final Exception exn = Exception('Error');
signals.addHandler(signalUnderTest, (ProcessSignal s) {
- throw 'Error';
+ throw exn;
});
final Completer<void> completer = Completer<void>();
@@ -75,7 +76,7 @@
controller.add(mockSignal);
await completer.future;
await errSub.cancel();
- expect(errList, <Object>['Error']);
+ expect(errList, contains(exn));
}, overrides: <Type, Generator>{
Signals: () => Signals(),
});
diff --git a/packages/flutter_tools/test/general.shard/build_info_test.dart b/packages/flutter_tools/test/general.shard/build_info_test.dart
index 6bff476b..6fdd169 100644
--- a/packages/flutter_tools/test/general.shard/build_info_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_info_test.dart
@@ -91,6 +91,6 @@
expect(getIOSArchForName('arm64'), DarwinArch.arm64);
expect(getIOSArchForName('arm64e'), DarwinArch.arm64);
expect(getIOSArchForName('x86_64'), DarwinArch.x86_64);
- expect(() => getIOSArchForName('bogus'), throwsAssertionError);
+ expect(() => getIOSArchForName('bogus'), throwsException);
});
}
diff --git a/packages/flutter_tools/test/general.shard/cache_test.dart b/packages/flutter_tools/test/general.shard/cache_test.dart
index 2c29c7e..7af793f 100644
--- a/packages/flutter_tools/test/general.shard/cache_test.dart
+++ b/packages/flutter_tools/test/general.shard/cache_test.dart
@@ -231,7 +231,7 @@
null,
});
fail('Mock thrown exception expected');
- } catch (e) {
+ } on Exception {
verify(artifact1.update());
// Don't continue when retrieval fails.
verifyNever(artifact2.update());
diff --git a/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart b/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart
index fab0c2b..e0f8fb0 100644
--- a/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart
+++ b/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart
@@ -152,6 +152,26 @@
.thenAnswer((_) => Future<Process>.value(process));
when(mockProcessManager.canRun(any)).thenReturn(false);
+ when(mockProcessManager.runSync(
+ argThat(contains(contains('gen_snapshot'))),
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 255, '', ''));
+
+ when(mockProcessManager.runSync(
+ <String>['/usr/bin/xcode-select', '--print-path'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 0, '', ''));
+
+ when(mockProcessManager.run(
+ <String>['which', 'pod'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenAnswer((_) {
+ return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
+ });
+
mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.directory).thenReturn('irrelevant');
});
diff --git a/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart b/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart
index 1dec6a0..f0c3e99 100644
--- a/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart
+++ b/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart
@@ -9,12 +9,11 @@
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
-
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_appbundle.dart';
+import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
-import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
@@ -135,6 +134,26 @@
.thenAnswer((_) => Future<Process>.value(process));
when(mockProcessManager.canRun(any)).thenReturn(false);
+ when(mockProcessManager.runSync(
+ argThat(contains(contains('gen_snapshot'))),
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 255, '', ''));
+
+ when(mockProcessManager.runSync(
+ <String>['/usr/bin/xcode-select', '--print-path'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenReturn(ProcessResult(0, 0, '', ''));
+
+ when(mockProcessManager.run(
+ <String>['which', 'pod'],
+ workingDirectory: anyNamed('workingDirectory'),
+ environment: anyNamed('environment'),
+ )).thenAnswer((_) {
+ return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
+ });
+
mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.validateSdkWellFormed()).thenReturn(const <String>[]);
when(mockAndroidSdk.directory).thenReturn('irrelevant');
diff --git a/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart b/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
index cd51b15..093008b 100644
--- a/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
+++ b/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
@@ -327,8 +327,7 @@
try {
await pub.get(context: PubContext.flutterTests, checkLastModified: true);
expect(true, isFalse, reason: 'pub.get did not throw');
- } catch (error) {
- expect(error, isA<Exception>());
+ } on ToolExit catch (error) {
expect(error.message, '/: unexpected concurrent modification of pubspec.yaml while running pub.');
}
expect(testLogger.statusText, 'Running "flutter pub get" in /...\n');
diff --git a/packages/flutter_tools/test/general.shard/devfs_test.dart b/packages/flutter_tools/test/general.shard/devfs_test.dart
index ce6e0e5..e09934e 100644
--- a/packages/flutter_tools/test/general.shard/devfs_test.dart
+++ b/packages/flutter_tools/test/general.shard/devfs_test.dart
@@ -136,7 +136,7 @@
const int kFailedAttempts = 5;
when(httpRequest.close()).thenAnswer((Invocation invocation) {
if (nRequest++ < kFailedAttempts) {
- throw 'Connection resert by peer';
+ throw Exception('Connection resert by peer');
}
return Future<HttpClientResponse>.value(httpClientResponse);
});
diff --git a/packages/flutter_tools/test/general.shard/flutter_platform_test.dart b/packages/flutter_tools/test/general.shard/flutter_platform_test.dart
index 13ef1af..6a0a98b 100644
--- a/packages/flutter_tools/test/general.shard/flutter_platform_test.dart
+++ b/packages/flutter_tools/test/general.shard/flutter_platform_test.dart
@@ -46,8 +46,17 @@
Future<Map<String, String>> captureEnvironment() async {
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
+ when(mockProcessManager.start(
+ any,
+ environment: anyNamed('environment')),
+ ).thenAnswer((_) {
+ return Future<Process>.value(MockProcess());
+ });
await untilCalled(mockProcessManager.start(any, environment: anyNamed('environment')));
- final VerificationResult toVerify = verify(mockProcessManager.start(any, environment: captureAnyNamed('environment')));
+ final VerificationResult toVerify = verify(mockProcessManager.start(
+ any,
+ environment: captureAnyNamed('environment'),
+ ));
expect(toVerify.captured, hasLength(1));
expect(toVerify.captured.first, isA<Map<String, String>>());
return toVerify.captured.first as Map<String, String>;
@@ -146,6 +155,8 @@
class MockProcessManager extends Mock implements ProcessManager {}
+class MockProcess extends Mock implements Process {}
+
class MockPlatform extends Mock implements Platform {}
class MockHttpServer extends Mock implements HttpServer {}
diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
index 66b6922..1f48f0b 100644
--- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
+++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
@@ -476,7 +476,7 @@
try {
await device.takeScreenshot(globals.fs.file('file.ppm'));
- } catch (_) {
+ } on Exception {
assert(false);
}
expect(
@@ -534,8 +534,8 @@
try {
await device.takeScreenshot(globals.fs.file('file.ppm'));
- } catch (_) {
- assert(false);
+ } on Exception catch (e) {
+ fail('Unexpected exception: $e');
}
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
diff --git a/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart b/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart
index 7fc9fd0..f00d5aa 100644
--- a/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart
@@ -229,9 +229,9 @@
Map<String, String> signingConfigs;
try {
signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
- } catch (e) {
+ } on Exception catch (e) {
// This should not throw
- expect(true, false);
+ fail('Code signing threw: $e');
}
expect(testLogger.statusText, contains('Apple Development: Profile 1 (1111AAAA11)'));
diff --git a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
index 441058c..1bfb6e0 100644
--- a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
@@ -54,7 +54,7 @@
expect(portForwarder.forwardedPorts.length, 2);
try {
await portForwarder.dispose();
- } catch (e) {
+ } on Exception catch (e) {
fail('Encountered exception: $e');
}
expect(portForwarder.forwardedPorts.length, 0);
diff --git a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart
index ebfd87b..8d1b459 100644
--- a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart
+++ b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart
@@ -355,7 +355,7 @@
engineDir: 'engine/path',
);
fail('ToolExit expected');
- } catch(e) {
+ } on Exception catch (e) {
expect(e, isA<ToolExit>());
verifyNever(mockProcessManager.run(
argThat(containsAllInOrder(<String>['pod', 'install'])),
@@ -404,7 +404,7 @@
engineDir: 'engine/path',
);
fail('ToolExit expected');
- } catch (e) {
+ } on Exception catch (e) {
expect(e, isA<ToolExit>());
expect(
testLogger.errorText,
diff --git a/packages/flutter_tools/test/integration.shard/test_driver.dart b/packages/flutter_tools/test/integration.shard/test_driver.dart
index d361d16..586d9eb 100644
--- a/packages/flutter_tools/test/integration.shard/test_driver.dart
+++ b/packages/flutter_tools/test/integration.shard/test_driver.dart
@@ -528,7 +528,7 @@
// have already completed.
_currentRunningAppId = (await started)['params']['appId'] as String;
prematureExitGuard.complete();
- } catch (error, stackTrace) {
+ } on Exception catch (error, stackTrace) {
prematureExitGuard.completeError(error, stackTrace);
}
}());
@@ -732,7 +732,7 @@
Map<String, dynamic> _parseJsonResponse(String line) {
try {
return castStringKeyedMap(json.decode(line));
- } catch (e) {
+ } on Exception {
// Not valid JSON, so likely some other output.
return null;
}
@@ -771,7 +771,7 @@
try {
final Map<String, dynamic> response = castStringKeyedMap(json.decode(line)[0]);
return response;
- } catch (e) {
+ } on Exception {
// Not valid JSON, so likely some other output that was surrounded by [brackets]
return null;
}
diff --git a/packages/flutter_tools/test/src/common.dart b/packages/flutter_tools/test/src/common.dart
index fb446bc..763c9db 100644
--- a/packages/flutter_tools/test/src/common.dart
+++ b/packages/flutter_tools/test/src/common.dart
@@ -139,7 +139,8 @@
fail('ToolExit expected, but nothing thrown');
} on ToolExit catch(e) {
expect(e.message, messageMatcher);
- } catch(e, trace) {
+ // Catch all exceptions to give a better test failure message.
+ } catch (e, trace) { // ignore: avoid_catches_without_on_clauses
fail('ToolExit expected, got $e\n$trace');
}
}
diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart
index cc21105..868f5a6 100644
--- a/packages/flutter_tools/test/src/context.dart
+++ b/packages/flutter_tools/test/src/context.dart
@@ -151,7 +151,8 @@
return await testMethod();
},
);
- } catch (error) {
+ // This catch rethrows, so doesn't need to catch only Exception.
+ } catch (error) { // ignore: avoid_catches_without_on_clauses
_printBufferedErrors(context);
rethrow;
}
diff --git a/packages/flutter_tools/test/src/mocks.dart b/packages/flutter_tools/test/src/mocks.dart
index dc6bab5..08c3c77 100644
--- a/packages/flutter_tools/test/src/mocks.dart
+++ b/packages/flutter_tools/test/src/mocks.dart
@@ -398,7 +398,8 @@
(List<int> data) {
try {
add(data);
- } catch (err, stack) {
+ // Catches all exceptions to propagate them to the completer.
+ } catch (err, stack) { // ignore: avoid_catches_without_on_clauses
sub.cancel();
completer.completeError(err, stack);
}