Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 1546fa0

Browse files
[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
1 parent 42b20cf commit 1546fa0

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

packages/flutter_tools/lib/src/android/android_workflow.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ class AndroidLicenseValidator extends DoctorValidator {
439439
.then(
440440
(Object? socket) => socket,
441441
onError: (dynamic err, StackTrace stack) {
442-
_logger.printError('Echoing stdin to the licenses subprocess failed:');
443-
_logger.printError('$err\n$stack');
442+
_logger.printTrace('Echoing stdin to the licenses subprocess failed:');
443+
_logger.printTrace('$err\n$stack');
444444
},
445445
),
446446
);
@@ -453,12 +453,19 @@ class AndroidLicenseValidator extends DoctorValidator {
453453
_stdio.addStderrStream(process.stderr),
454454
]);
455455
} on Exception catch (err, stack) {
456-
_logger.printError('Echoing stdout or stderr from the license subprocess failed:');
457-
_logger.printError('$err\n$stack');
456+
_logger.printTrace('Echoing stdout or stderr from the license subprocess failed:');
457+
_logger.printTrace('$err\n$stack');
458458
}
459459

460460
final int exitCode = await process.exitCode;
461-
return exitCode == 0;
461+
if (exitCode != 0) {
462+
throwToolExit(_userMessages.androidCannotRunSdkManager(
463+
_androidSdk?.sdkManagerPath ?? '',
464+
'exited code $exitCode',
465+
_platform,
466+
));
467+
}
468+
return true;
462469
} on ProcessException catch (e) {
463470
throwToolExit(_userMessages.androidCannotRunSdkManager(
464471
_androidSdk?.sdkManagerPath ?? '',

packages/flutter_tools/test/general.shard/android/android_workflow_test.dart

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Review licenses that have not been accepted (y/N)?
339339
);
340340

341341
await licenseValidator.runLicenseManager();
342-
expect(logger.errorText, contains(exceptionMessage));
342+
expect(logger.traceText, contains(exceptionMessage));
343343
expect(processManager, hasNoRemainingExpectations);
344344
});
345345

@@ -362,6 +362,42 @@ Review licenses that have not been accepted (y/N)?
362362
expect(licenseValidator.runLicenseManager(), throwsToolExit());
363363
});
364364

365+
testWithoutContext('runLicenseManager errors when sdkmanager exits non-zero', () async {
366+
const String sdkManagerPath = '/foo/bar/sdkmanager';
367+
sdk.sdkManagerPath = sdkManagerPath;
368+
final BufferLogger logger = BufferLogger.test();
369+
processManager.addCommand(
370+
const FakeCommand(
371+
command: <String>[sdkManagerPath, '--licenses'],
372+
exitCode: 1,
373+
stderr: 'sdkmanager crash',
374+
),
375+
);
376+
377+
final AndroidLicenseValidator licenseValidator = AndroidLicenseValidator(
378+
androidSdk: sdk,
379+
fileSystem: fileSystem,
380+
processManager: processManager,
381+
platform: FakePlatform(environment: <String, String>{'HOME': '/home/me'}),
382+
stdio: stdio,
383+
logger: logger,
384+
userMessages: UserMessages(),
385+
androidStudio: FakeAndroidStudio(),
386+
operatingSystemUtils: FakeOperatingSystemUtils(),
387+
);
388+
389+
await expectLater(
390+
licenseValidator.runLicenseManager(),
391+
throwsToolExit(
392+
message: 'Android sdkmanager tool was found, but failed to run ($sdkManagerPath): "exited code 1"',
393+
),
394+
);
395+
expect(processManager, hasNoRemainingExpectations);
396+
expect(logger.traceText, isEmpty);
397+
expect(stdio.writtenToStdout, isEmpty);
398+
expect(stdio.writtenToStderr, contains('sdkmanager crash'));
399+
});
400+
365401
testWithoutContext('detects license-only SDK installation with cmdline-tools', () async {
366402
sdk
367403
..licensesAvailable = true

0 commit comments

Comments
 (0)