From 8e6205fe1dde543412f559027a69eb710c080378 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 7 Aug 2019 17:00:36 -0700 Subject: [PATCH] Handle thrown maps and rejects from fe server (#37743) --- packages/flutter_tools/lib/src/compile.dart | 2 +- .../lib/src/resident_runner.dart | 24 +++++++------------ packages/flutter_tools/lib/src/run_hot.dart | 3 +-- packages/flutter_tools/lib/src/vmservice.dart | 2 +- .../test/general.shard/compile_test.dart | 11 ++++----- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 4858710ec2..f90902721d 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -653,7 +653,7 @@ class ResidentCompiler { if (!_compileRequestNeedsConfirmation) { return Future.value(null); } - _stdoutHandler.reset(); + _stdoutHandler.reset(expectSources: false); _server.stdin.writeln('reject'); printTrace('<- reject'); _compileRequestNeedsConfirmation = false; diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 167b402392..14091bf9ef 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -540,12 +540,10 @@ abstract class ResidentRunner { this.stayResident = true, this.hotMode = true, this.dillOutputPath, - }) { - _mainPath = findMainDartFile(target); - _projectRootPath = projectRootPath ?? fs.currentDirectory.path; - _packagesFilePath = - packagesFilePath ?? fs.path.absolute(PackageMap.globalPackagesPath); - _assetBundle = AssetBundleFactory.instance.createBundle(); + }) : mainPath = findMainDartFile(target), + projectRootPath = projectRootPath ?? fs.currentDirectory.path, + packagesFilePath = packagesFilePath ?? fs.path.absolute(PackageMap.globalPackagesPath), + assetBundle = AssetBundleFactory.instance.createBundle() { // TODO(jonahwilliams): this is transitionary logic to allow us to support // platforms that are not yet using flutter assemble. In the "new world", // builds are isolated based on a number of factors. Thus, we cannot assume @@ -570,19 +568,15 @@ abstract class ResidentRunner { final bool ipv6; final Completer _finished = Completer(); final String dillOutputPath; + final String packagesFilePath; + final String projectRootPath; + final String mainPath; + final AssetBundle assetBundle; + bool _exited = false; bool hotMode ; - String _packagesFilePath; - String get packagesFilePath => _packagesFilePath; - String _projectRootPath; - String get projectRootPath => _projectRootPath; - String _mainPath; - String get mainPath => _mainPath; String getReloadPath({ bool fullRestart }) => mainPath + (fullRestart ? '' : '.incremental') + '.dill'; - AssetBundle _assetBundle; - AssetBundle get assetBundle => _assetBundle; - bool get isRunningDebug => debuggingOptions.buildInfo.isDebug; bool get isRunningProfile => debuggingOptions.buildInfo.isProfile; bool get isRunningRelease => debuggingOptions.buildInfo.isRelease; diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index b834a81269..4a7ea38877 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -654,7 +654,7 @@ class HotRunner extends ResidentRunner { for (FlutterDevice device in flutterDevices) { for (FlutterView view in device.views) { if (view.uiIsolate == null) { - throw 'Application isolate not found'; + return OperationResult(2, 'Application isolate not found', fatal: true); } } } @@ -762,7 +762,6 @@ class HotRunner extends ResidentRunner { } // Record time it took for the VM to reload the sources. _addBenchmarkData('hotReloadVMReloadMilliseconds', vmReloadTimer.elapsed.inMilliseconds); - final Stopwatch reassembleTimer = Stopwatch()..start(); // Reload the isolate. final List> allDevices = >[]; diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 777323c354..b55f4da769 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -1177,7 +1177,7 @@ class Isolate extends ServiceObjectOwner { final Map response = await invokeRpcRaw('_reloadSources', params: arguments); return response; } on rpc.RpcException catch (e) { - return Future>.error({ + return Future>.value({ 'code': e.code, 'message': e.message, 'data': e.data, diff --git a/packages/flutter_tools/test/general.shard/compile_test.dart b/packages/flutter_tools/test/general.shard/compile_test.dart index 16743a23ef..c9257a9255 100644 --- a/packages/flutter_tools/test/general.shard/compile_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_test.dart @@ -266,7 +266,6 @@ example:org-dartlang-app:/ testUsingContext('compile and recompile', () async { final BufferLogger logger = context.get(); - final StreamController> streamController = StreamController>(); when(mockFrontendServer.stdout) .thenAnswer((Invocation invocation) => streamController.stream); @@ -289,11 +288,10 @@ example:org-dartlang-app:/ await _accept(streamController, generator, mockFrontendServerStdIn, '^accept\\n\$'); await _recompile(streamController, generator, mockFrontendServerStdIn, - 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n'); - - await _reject(streamController, generator, mockFrontendServerStdIn, 'result abc\nabc\nabc\nabc', - '^reject\\n\$'); - + 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n'); + // No sources returned from reject command. + await _reject(streamController, generator, mockFrontendServerStdIn, 'result abc\nabc\n', + '^reject\\n\$'); verifyNoMoreInteractions(mockFrontendServerStdIn); expect(mockFrontendServerStdIn.getAndClear(), isEmpty); expect(logger.errorText, equals( @@ -578,7 +576,6 @@ Future _reject( expect(commands, matches(re)); mockFrontendServerStdIn._stdInWrites.clear(); } - class MockProcessManager extends Mock implements ProcessManager {} class MockProcess extends Mock implements Process {} class MockStream extends Mock implements Stream> {}