[flutter_tool] Where possible, catch only subtypes of Exception (#51440)
This commit is contained in:
@@ -177,7 +177,7 @@ class AndroidDevice extends Device {
|
||||
} finally {
|
||||
console.destroy();
|
||||
}
|
||||
} catch (e) {
|
||||
} on Exception catch (e) {
|
||||
globals.printTrace('Failed to fetch avd name for emulator at $host:$port: $e');
|
||||
// If we fail to connect to the device, we should not fail so just return
|
||||
// an empty name. This data is best-effort.
|
||||
@@ -299,7 +299,7 @@ class AndroidDevice extends Device {
|
||||
return true;
|
||||
}
|
||||
globals.printError('The ADB at "${getAdbPath(androidSdk)}" is too old; please install version 1.0.39 or later.');
|
||||
} catch (error, trace) {
|
||||
} on Exception catch (error, trace) {
|
||||
globals.printError('Error running ADB: $error', stackTrace: trace);
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e, stacktrace) {
|
||||
} on Exception catch (e, stacktrace) {
|
||||
globals.printError('Unexpected failure from adb: $e');
|
||||
globals.printError('Stacktrace: $stacktrace');
|
||||
return false;
|
||||
@@ -366,7 +366,7 @@ class AndroidDevice extends Device {
|
||||
try {
|
||||
final RunResult listOut = await runAdbCheckedAsync(<String>['shell', 'pm', 'list', 'packages', app.id]);
|
||||
return LineSplitter.split(listOut.stdout).contains('package:${app.id}');
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
globals.printTrace('$error');
|
||||
return false;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ class AndroidDevice extends Device {
|
||||
throwOnError: true,
|
||||
);
|
||||
uninstallOut = uninstallResult.stdout;
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
globals.printError('adb uninstall failed: $error');
|
||||
return false;
|
||||
}
|
||||
@@ -631,7 +631,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
globals.printError('Error waiting for a debug connection: $error');
|
||||
return LaunchResult.failed();
|
||||
} finally {
|
||||
@@ -696,7 +696,7 @@ class AndroidDevice extends Device {
|
||||
output = runAdbCheckedSync(<String>[
|
||||
'shell', '-x', 'logcat', '-v', 'time', '-t', '1'
|
||||
]);
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
globals.printError('Failed to extract the most recent timestamp from the Android log: $error.');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ class AndroidSdk {
|
||||
.map((FileSystemEntity entity) {
|
||||
try {
|
||||
return Version.parse(entity.basename);
|
||||
} catch (error) {
|
||||
} on Exception {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
@@ -518,7 +518,7 @@ class AndroidSdk {
|
||||
.group(1);
|
||||
platformVersion = int.parse(versionString);
|
||||
}
|
||||
} catch (error) {
|
||||
} on Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ class AndroidSdk {
|
||||
return fileSystem.path.join(javaHome, 'bin', 'java');
|
||||
}
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
} on Exception catch (_) { /* ignore */ }
|
||||
}
|
||||
|
||||
// Fallback to PATH based lookup.
|
||||
|
||||
@@ -93,7 +93,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
installPath = globals.fs
|
||||
.file(globals.fs.path.join(homeDotDir.path, 'system', '.home'))
|
||||
.readAsStringSync();
|
||||
} catch (e) {
|
||||
} on Exception {
|
||||
// ignored, installPath will be null, which is handled below
|
||||
}
|
||||
if (installPath != null && globals.fs.isDirectorySync(installPath)) {
|
||||
@@ -200,7 +200,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
_checkForStudio(directory.path);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} on Exception catch (e) {
|
||||
globals.printTrace('Exception while looking for Android Studio: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class AndroidValidator extends DoctorValidator {
|
||||
final List<String> versionLines = (result.stderr as String).split('\n');
|
||||
javaVersionText = versionLines.length >= 2 ? versionLines[1] : versionLines[0];
|
||||
}
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
_logger.printTrace(error.toString());
|
||||
}
|
||||
if (javaVersionText == null || javaVersionText.isEmpty) {
|
||||
@@ -287,7 +287,7 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
final List<String> versionLines = (result.stderr as String).split('\n');
|
||||
javaVersion = versionLines.length >= 2 ? versionLines[1] : versionLines[0];
|
||||
}
|
||||
} catch (error) {
|
||||
} on Exception catch (error) {
|
||||
globals.printTrace(error.toString());
|
||||
}
|
||||
if (javaVersion == null) {
|
||||
@@ -389,7 +389,7 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
globals.stdio.addStdoutStream(process.stdout),
|
||||
globals.stdio.addStderrStream(process.stderr),
|
||||
]);
|
||||
} catch (err, stack) {
|
||||
} on Exception catch (err, stack) {
|
||||
globals.printTrace('Echoing stdout or stderr from the license subprocess failed:');
|
||||
globals.printTrace('$err\n$stack');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user