Unverified Commit aa1df71c authored by Jia Hao's avatar Jia Hao Committed by GitHub

[flutter_tools] throwToolExit should return Never (#78954)

parent ea3d4dbd
...@@ -452,7 +452,6 @@ class AndroidLicenseValidator extends DoctorValidator { ...@@ -452,7 +452,6 @@ class AndroidLicenseValidator extends DoctorValidator {
e.toString(), e.toString(),
_platform, _platform,
)); ));
return false;
} }
} }
......
...@@ -1083,7 +1083,6 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) { ...@@ -1083,7 +1083,6 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) {
} }
} }
throwToolExit('Error while parsing the <version> element from $pomPath'); throwToolExit('Error while parsing the <version> element from $pomPath');
return null;
} }
/// Returns the local Maven repository for a local engine build. /// Returns the local Maven repository for a local engine build.
......
...@@ -65,7 +65,6 @@ class GradleUtils { ...@@ -65,7 +65,6 @@ class GradleUtils {
'Unable to locate gradlew script. Please check that ${gradle.path} ' 'Unable to locate gradlew script. Please check that ${gradle.path} '
'exists or that ${gradle.dirname} can be read.' 'exists or that ${gradle.dirname} can be read.'
); );
return null;
} }
/// Injects the Gradle wrapper files if any of these files don't exist in [directory]. /// Injects the Gradle wrapper files if any of these files don't exist in [directory].
...@@ -180,7 +179,6 @@ String getGradleVersionFor(String androidPluginVersion) { ...@@ -180,7 +179,6 @@ String getGradleVersionFor(String androidPluginVersion) {
return '6.7'; return '6.7';
} }
throwToolExit('Unsupported Android Plugin version: $androidPluginVersion.'); throwToolExit('Unsupported Android Plugin version: $androidPluginVersion.');
return '';
} }
/// Overwrite local.properties in the specified Flutter project's Android /// Overwrite local.properties in the specified Flutter project's Android
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
/// where the tool should exit with a clear message to the user /// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified. /// and no stack trace unless the --verbose option is specified.
/// For example: network errors. /// For example: network errors.
void throwToolExit(String message, { int? exitCode }) { Never throwToolExit(String message, { int? exitCode }) {
throw ToolExit(message, exitCode: exitCode); throw ToolExit(message, exitCode: exitCode);
} }
......
...@@ -76,7 +76,6 @@ class DartDevelopmentService { ...@@ -76,7 +76,6 @@ class DartDevelopmentService {
} on StateError { } on StateError {
if (e.message.contains('Existing VM service clients prevent DDS from taking control.')) { if (e.message.contains('Existing VM service clients prevent DDS from taking control.')) {
throwToolExit('${e.message}. Please rebuild your application with a newer version of Flutter.'); throwToolExit('${e.message}. Please rebuild your application with a newer version of Flutter.');
return;
} }
logger.printError( logger.printError(
'DDS has failed to start and there is not an existing DDS instance ' 'DDS has failed to start and there is not an existing DDS instance '
......
...@@ -338,7 +338,7 @@ class _MacOSUtils extends _PosixUtils { ...@@ -338,7 +338,7 @@ class _MacOSUtils extends _PosixUtils {
throwToolExit('sysctl not found. Try adding it to your PATH environment variable.'); throwToolExit('sysctl not found. Try adding it to your PATH environment variable.');
} }
final RunResult arm64Check = final RunResult arm64Check =
_processUtils.runSync(<String>[sysctlPath!, 'hw.optional.arm64']); _processUtils.runSync(<String>[sysctlPath, 'hw.optional.arm64']);
// On arm64 stdout is "sysctl hw.optional.arm64: 1" // On arm64 stdout is "sysctl hw.optional.arm64: 1"
// On x86 hw.optional.arm64 is unavailable and exits with 1. // On x86 hw.optional.arm64 is unavailable and exits with 1.
if (arm64Check.exitCode == 0 && arm64Check.stdout.trim().endsWith('1')) { if (arm64Check.exitCode == 0 && arm64Check.stdout.trim().endsWith('1')) {
...@@ -376,7 +376,7 @@ class _WindowsUtils extends OperatingSystemUtils { ...@@ -376,7 +376,7 @@ class _WindowsUtils extends OperatingSystemUtils {
@override @override
List<File> _which(String execName, { bool all = false }) { List<File> _which(String execName, { bool all = false }) {
// `where` always returns all matches, not just the first one. // `where` always returns all matches, not just the first one.
ProcessResult? result; ProcessResult result;
try { try {
result = _processManager.runSync(<String>['where', execName]); result = _processManager.runSync(<String>['where', execName]);
} on ArgumentError { } on ArgumentError {
...@@ -388,10 +388,10 @@ class _WindowsUtils extends OperatingSystemUtils { ...@@ -388,10 +388,10 @@ class _WindowsUtils extends OperatingSystemUtils {
'the terminal and/or IDE.' 'the terminal and/or IDE.'
); );
} }
if (result?.exitCode != 0) { if (result.exitCode != 0) {
return const <File>[]; return const <File>[];
} }
final List<String> lines = (result!.stdout as String).trim().split('\n'); final List<String> lines = (result.stdout as String).trim().split('\n');
if (all) { if (all) {
return lines.map<File>((String path) => _fileSystem.file(path.trim())).toList(); return lines.map<File>((String path) => _fileSystem.file(path.trim())).toList();
} }
......
...@@ -149,7 +149,6 @@ known, it can be explicitly provided to attach via the command-line, e.g. ...@@ -149,7 +149,6 @@ known, it can be explicitly provided to attach via the command-line, e.g.
} on Exception catch (error) { } on Exception catch (error) {
throwToolExit('Invalid port for `--debug-port`: $error'); throwToolExit('Invalid port for `--debug-port`: $error');
} }
return null;
} }
Uri get debugUri { Uri get debugUri {
......
...@@ -220,7 +220,6 @@ class UpgradeCommandRunner { ...@@ -220,7 +220,6 @@ class UpgradeCommandRunner {
'Error: $error.' 'Error: $error.'
); );
} }
return false;
} }
/// Returns the remote HEAD flutter version. /// Returns the remote HEAD flutter version.
......
...@@ -622,13 +622,11 @@ class FuchsiaDevice extends Device { ...@@ -622,13 +622,11 @@ class FuchsiaDevice extends Device {
final RunResult findResult = await shell(findCommand); final RunResult findResult = await shell(findCommand);
if (findResult.exitCode != 0) { if (findResult.exitCode != 0) {
throwToolExit("'$findCommand' on device $name failed. stderr: '${findResult.stderr}'"); throwToolExit("'$findCommand' on device $name failed. stderr: '${findResult.stderr}'");
return null;
} }
final String findOutput = findResult.stdout; final String findOutput = findResult.stdout;
if (findOutput.trim() == '') { if (findOutput.trim() == '') {
throwToolExit( throwToolExit(
'No Dart Observatories found. Are you running a debug build?'); 'No Dart Observatories found. Are you running a debug build?');
return null;
} }
final List<int> ports = <int>[]; final List<int> ports = <int>[];
for (final String path in findOutput.split('\n')) { for (final String path in findOutput.split('\n')) {
...@@ -639,7 +637,6 @@ class FuchsiaDevice extends Device { ...@@ -639,7 +637,6 @@ class FuchsiaDevice extends Device {
final RunResult lsResult = await shell(lsCommand); final RunResult lsResult = await shell(lsCommand);
if (lsResult.exitCode != 0) { if (lsResult.exitCode != 0) {
throwToolExit("'$lsCommand' on device $name failed"); throwToolExit("'$lsCommand' on device $name failed");
return null;
} }
final String lsOutput = lsResult.stdout; final String lsOutput = lsResult.stdout;
for (final String line in lsOutput.split('\n')) { for (final String line in lsOutput.split('\n')) {
...@@ -715,7 +712,6 @@ class FuchsiaDevice extends Device { ...@@ -715,7 +712,6 @@ class FuchsiaDevice extends Device {
} }
} }
throwToolExit('No ports found running $isolateName'); throwToolExit('No ports found running $isolateName');
return null;
} }
FuchsiaIsolateDiscoveryProtocol getIsolateDiscoveryProtocol(String isolateName) { FuchsiaIsolateDiscoveryProtocol getIsolateDiscoveryProtocol(String isolateName) {
......
...@@ -563,7 +563,6 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -563,7 +563,6 @@ class ResidentWebRunner extends ResidentRunner {
appFailedToStart(); appFailedToStart();
rethrow; rethrow;
} }
return 0;
} }
@override @override
......
...@@ -392,7 +392,6 @@ class CocoaPods { ...@@ -392,7 +392,6 @@ class CocoaPods {
'To regenerate the Podfile, run:\n' 'To regenerate the Podfile, run:\n'
'$podfileIosMigrationInstructions\n', '$podfileIosMigrationInstructions\n',
); );
return;
} }
} }
// Most of the pod and plugin parsing logic was moved from the Podfile // Most of the pod and plugin parsing logic was moved from the Podfile
......
...@@ -378,7 +378,6 @@ abstract class FlutterCommand extends Command<void> { ...@@ -378,7 +378,6 @@ abstract class FlutterCommand extends Command<void> {
} on FormatException catch (error) { } on FormatException catch (error) {
throwToolExit('Invalid port for `--observatory-port/--host-vmservice-port`: $error'); throwToolExit('Invalid port for `--observatory-port/--host-vmservice-port`: $error');
} }
return null;
} }
int get ddsPort { int get ddsPort {
...@@ -440,7 +439,6 @@ abstract class FlutterCommand extends Command<void> { ...@@ -440,7 +439,6 @@ abstract class FlutterCommand extends Command<void> {
} on FormatException catch (error) { } on FormatException catch (error) {
throwToolExit('Invalid port for `--device-vmservice-port`: $error'); throwToolExit('Invalid port for `--device-vmservice-port`: $error');
} }
return null;
} }
void addPublishPort({ bool enabledByDefault = true, bool verboseHelp = false }) { void addPublishPort({ bool enabledByDefault = true, bool verboseHelp = false }) {
......
...@@ -112,7 +112,6 @@ class Template { ...@@ -112,7 +112,6 @@ class Template {
} on FileSystemException catch (err) { } on FileSystemException catch (err) {
_logger.printError(err.toString()); _logger.printError(err.toString());
throwToolExit('Failed to flutter create at ${destination.path}.'); throwToolExit('Failed to flutter create at ${destination.path}.');
return 0;
} }
int fileCount = 0; int fileCount = 0;
......
...@@ -638,7 +638,6 @@ class BrowserManager { ...@@ -638,7 +638,6 @@ class BrowserManager {
return completer.future.timeout(const Duration(seconds: 30), onTimeout: () { return completer.future.timeout(const Duration(seconds: 30), onTimeout: () {
chrome.close(); chrome.close();
throwToolExit('Timed out waiting for ${runtime.name} to connect.'); throwToolExit('Timed out waiting for ${runtime.name} to connect.');
return;
}); });
} }
......
...@@ -81,7 +81,6 @@ String findChromeExecutable(Platform platform, FileSystem fileSystem) { ...@@ -81,7 +81,6 @@ String findChromeExecutable(Platform platform, FileSystem fileSystem) {
return fileSystem.path.join(windowsPrefix, kWindowsExecutable); return fileSystem.path.join(windowsPrefix, kWindowsExecutable);
} }
throwToolExit('Platform ${platform.operatingSystem} is not supported.'); throwToolExit('Platform ${platform.operatingSystem} is not supported.');
return null;
} }
/// Find the Microsoft Edge executable on the current platform. /// Find the Microsoft Edge executable on the current platform.
......
...@@ -241,7 +241,6 @@ void main() { ...@@ -241,7 +241,6 @@ void main() {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand( final DummyFlutterCommand flutterCommand = DummyFlutterCommand(
commandFunction: () async { commandFunction: () async {
throwToolExit('fail'); throwToolExit('fail');
return null; // unreachable
} }
); );
try { try {
...@@ -469,7 +468,6 @@ void main() { ...@@ -469,7 +468,6 @@ void main() {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand( final DummyFlutterCommand flutterCommand = DummyFlutterCommand(
commandFunction: () async { commandFunction: () async {
throwToolExit('fail'); throwToolExit('fail');
return null; // unreachable
}, },
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment