Unverified Commit 1546fa08 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] toolExit on sdkmanager exit during doctor --android-licenses (#120330)

* tool exit on sdk manager exit and add test

* be more specific about error message
parent 42b20cf9
...@@ -439,8 +439,8 @@ class AndroidLicenseValidator extends DoctorValidator { ...@@ -439,8 +439,8 @@ class AndroidLicenseValidator extends DoctorValidator {
.then( .then(
(Object? socket) => socket, (Object? socket) => socket,
onError: (dynamic err, StackTrace stack) { onError: (dynamic err, StackTrace stack) {
_logger.printError('Echoing stdin to the licenses subprocess failed:'); _logger.printTrace('Echoing stdin to the licenses subprocess failed:');
_logger.printError('$err\n$stack'); _logger.printTrace('$err\n$stack');
}, },
), ),
); );
...@@ -453,12 +453,19 @@ class AndroidLicenseValidator extends DoctorValidator { ...@@ -453,12 +453,19 @@ class AndroidLicenseValidator extends DoctorValidator {
_stdio.addStderrStream(process.stderr), _stdio.addStderrStream(process.stderr),
]); ]);
} on Exception catch (err, stack) { } on Exception catch (err, stack) {
_logger.printError('Echoing stdout or stderr from the license subprocess failed:'); _logger.printTrace('Echoing stdout or stderr from the license subprocess failed:');
_logger.printError('$err\n$stack'); _logger.printTrace('$err\n$stack');
} }
final int exitCode = await process.exitCode; final int exitCode = await process.exitCode;
return exitCode == 0; if (exitCode != 0) {
throwToolExit(_userMessages.androidCannotRunSdkManager(
_androidSdk?.sdkManagerPath ?? '',
'exited code $exitCode',
_platform,
));
}
return true;
} on ProcessException catch (e) { } on ProcessException catch (e) {
throwToolExit(_userMessages.androidCannotRunSdkManager( throwToolExit(_userMessages.androidCannotRunSdkManager(
_androidSdk?.sdkManagerPath ?? '', _androidSdk?.sdkManagerPath ?? '',
......
...@@ -339,7 +339,7 @@ Review licenses that have not been accepted (y/N)? ...@@ -339,7 +339,7 @@ Review licenses that have not been accepted (y/N)?
); );
await licenseValidator.runLicenseManager(); await licenseValidator.runLicenseManager();
expect(logger.errorText, contains(exceptionMessage)); expect(logger.traceText, contains(exceptionMessage));
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
...@@ -362,6 +362,42 @@ Review licenses that have not been accepted (y/N)? ...@@ -362,6 +362,42 @@ Review licenses that have not been accepted (y/N)?
expect(licenseValidator.runLicenseManager(), throwsToolExit()); expect(licenseValidator.runLicenseManager(), throwsToolExit());
}); });
testWithoutContext('runLicenseManager errors when sdkmanager exits non-zero', () async {
const String sdkManagerPath = '/foo/bar/sdkmanager';
sdk.sdkManagerPath = sdkManagerPath;
final BufferLogger logger = BufferLogger.test();
processManager.addCommand(
const FakeCommand(
command: <String>[sdkManagerPath, '--licenses'],
exitCode: 1,
stderr: 'sdkmanager crash',
),
);
final AndroidLicenseValidator licenseValidator = AndroidLicenseValidator(
androidSdk: sdk,
fileSystem: fileSystem,
processManager: processManager,
platform: FakePlatform(environment: <String, String>{'HOME': '/home/me'}),
stdio: stdio,
logger: logger,
userMessages: UserMessages(),
androidStudio: FakeAndroidStudio(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
await expectLater(
licenseValidator.runLicenseManager(),
throwsToolExit(
message: 'Android sdkmanager tool was found, but failed to run ($sdkManagerPath): "exited code 1"',
),
);
expect(processManager, hasNoRemainingExpectations);
expect(logger.traceText, isEmpty);
expect(stdio.writtenToStdout, isEmpty);
expect(stdio.writtenToStderr, contains('sdkmanager crash'));
});
testWithoutContext('detects license-only SDK installation with cmdline-tools', () async { testWithoutContext('detects license-only SDK installation with cmdline-tools', () async {
sdk sdk
..licensesAvailable = true ..licensesAvailable = true
......
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