[ tool ] Don't throw StateError when DDS fails to start (#158744)

This started happening after moving DDS to launch from `dart
development-service` rather than `DartDevelopmentService` (see
33b402d24c2131dcf97e272ec3d59c0249762e7f) . This state error was
originally meant to be thrown when some string parsing failed, but is
currently wrapping the `DartDevelopmentServiceException`.

Fixes https://github.com/flutter/flutter/issues/158537
This commit is contained in:
Ben Konyi 2024-11-14 19:43:15 -05:00 committed by GitHub
parent 34b5c274bb
commit d0bd283734
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 70 deletions

View File

@ -96,22 +96,11 @@ class DartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin {
Artifact.engineDartBinary, Artifact.engineDartBinary,
), ),
); );
// Complete the future if the DDS process is null, which happens in
// testing.
unawaited(_ddsInstance!.done.whenComplete(completeFuture)); unawaited(_ddsInstance!.done.whenComplete(completeFuture));
} on DartDevelopmentServiceException catch (e) { } on DartDevelopmentServiceException catch (e) {
_logger.printTrace('Warning: Failed to start DDS: ${e.message}'); _logger.printTrace('Warning: Failed to start DDS: ${e.message}');
if (e is ExistingDartDevelopmentServiceException) { if (e is ExistingDartDevelopmentServiceException) {
_existingDdsUri = e.ddsUri; _existingDdsUri = e.ddsUri;
} else {
_logger.printError(
'DDS has failed to start and there is not an existing DDS instance '
'available to connect to. Please file an issue at https://github.com/flutter/flutter/issues '
'with the following error message:\n\n ${e.message}.');
// DDS was unable to start for an unknown reason. Raise a StateError
// so it can be reported by the crash reporter.
throw StateError(e.message);
} }
completeFuture(); completeFuture();
rethrow; rethrow;

View File

@ -2021,65 +2021,6 @@ flutter:
}) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService, }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
})); }));
testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async {
// See https://github.com/flutter/flutter/issues/72385 for context.
final FakeDevice device = FakeDevice()
..dds = DartDevelopmentService(logger: testLogger);
ddsLauncherCallback = ({
required Uri remoteVmServiceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
String? google3WorkspaceRoot,
}) {
expect(remoteVmServiceUri, Uri(scheme: 'foo', host: 'bar'));
expect(enableAuthCodes, isTrue);
expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
expect(cachedUserTags, isEmpty);
throw FakeDartDevelopmentServiceException(message: 'No URI');
};
final TestFlutterDevice flutterDevice = TestFlutterDevice(
device,
vmServiceUris: Stream<Uri>.value(testUri),
);
bool caught = false;
final Completer<void>done = Completer<void>();
runZonedGuarded(() {
flutterDevice.connect(
allowExistingDdsInstance: true,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, enableDevTools: false),
).then((_) => done.complete());
}, (Object e, StackTrace st) {
expect(e, isA<StateError>());
expect((e as StateError).message, contains('No URI'));
expect(testLogger.errorText, contains(
'DDS has failed to start and there is not an existing DDS instance',
));
done.complete();
caught = true;
});
await done.future;
if (!caught) {
fail('Expected a StateError to be thrown.');
}
}, overrides: <Type, Generator>{
VMServiceConnector: () => (Uri httpUri, {
ReloadSources? reloadSources,
Restart? restart,
CompileExpression? compileExpression,
GetSkSLMethod? getSkSLMethod,
FlutterProject? flutterProject,
PrintStructuredErrorLogMethod? printStructuredErrorLogMethod,
io.CompressionOptions compression = io.CompressionOptions.compressionDefault,
Device? device,
required Logger logger,
}) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
}));
testUsingContext('nextPlatform moves through expected platforms', () { testUsingContext('nextPlatform moves through expected platforms', () {
expect(nextPlatform('android'), 'iOS'); expect(nextPlatform('android'), 'iOS');
expect(nextPlatform('iOS'), 'windows'); expect(nextPlatform('iOS'), 'windows');