Unverified Commit 5b9ce492 authored by Helin Shiah's avatar Helin Shiah Committed by GitHub

Skip printing rendered error text in machine mode (#61684)

parent c4bfa4c7
...@@ -53,6 +53,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory { ...@@ -53,6 +53,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
@required bool ipv6, @required bool ipv6,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
@required UrlTunneller urlTunneller, @required UrlTunneller urlTunneller,
bool machine = false,
}) { }) {
return _ResidentWebRunner( return _ResidentWebRunner(
device, device,
...@@ -62,6 +63,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory { ...@@ -62,6 +63,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
ipv6: ipv6, ipv6: ipv6,
stayResident: stayResident, stayResident: stayResident,
urlTunneller: urlTunneller, urlTunneller: urlTunneller,
machine: machine,
); );
} }
} }
...@@ -79,12 +81,14 @@ abstract class ResidentWebRunner extends ResidentRunner { ...@@ -79,12 +81,14 @@ abstract class ResidentWebRunner extends ResidentRunner {
@required bool ipv6, @required bool ipv6,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
bool stayResident = true, bool stayResident = true,
bool machine = false,
}) : super( }) : super(
<FlutterDevice>[device], <FlutterDevice>[device],
target: target ?? globals.fs.path.join('lib', 'main.dart'), target: target ?? globals.fs.path.join('lib', 'main.dart'),
debuggingOptions: debuggingOptions, debuggingOptions: debuggingOptions,
ipv6: ipv6, ipv6: ipv6,
stayResident: stayResident, stayResident: stayResident,
machine: machine,
); );
FlutterDevice get device => flutterDevices.first; FlutterDevice get device => flutterDevices.first;
...@@ -390,6 +394,7 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -390,6 +394,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
bool stayResident = true, bool stayResident = true,
@required this.urlTunneller, @required this.urlTunneller,
bool machine = false,
}) : super( }) : super(
device, device,
flutterProject: flutterProject, flutterProject: flutterProject,
...@@ -397,6 +402,7 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -397,6 +402,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
debuggingOptions: debuggingOptions, debuggingOptions: debuggingOptions,
ipv6: ipv6, ipv6: ipv6,
stayResident: stayResident, stayResident: stayResident,
machine: machine,
); );
final UrlTunneller urlTunneller; final UrlTunneller urlTunneller;
......
...@@ -448,6 +448,7 @@ class AppDomain extends Domain { ...@@ -448,6 +448,7 @@ class AppDomain extends Domain {
String dillOutputPath, String dillOutputPath,
bool ipv6 = false, bool ipv6 = false,
String isolateFilter, String isolateFilter,
bool machine = true,
}) async { }) async {
if (!await device.supportsRuntimeMode(options.buildInfo.mode)) { if (!await device.supportsRuntimeMode(options.buildInfo.mode)) {
throw Exception( throw Exception(
...@@ -480,6 +481,7 @@ class AppDomain extends Domain { ...@@ -480,6 +481,7 @@ class AppDomain extends Domain {
ipv6: ipv6, ipv6: ipv6,
stayResident: true, stayResident: true,
urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null, urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null,
machine: machine,
); );
} else if (enableHotReload) { } else if (enableHotReload) {
runner = HotRunner( runner = HotRunner(
...@@ -491,6 +493,7 @@ class AppDomain extends Domain { ...@@ -491,6 +493,7 @@ class AppDomain extends Domain {
dillOutputPath: dillOutputPath, dillOutputPath: dillOutputPath,
ipv6: ipv6, ipv6: ipv6,
hostIsIde: true, hostIsIde: true,
machine: machine,
); );
} else { } else {
runner = ColdRunner( runner = ColdRunner(
...@@ -499,6 +502,7 @@ class AppDomain extends Domain { ...@@ -499,6 +502,7 @@ class AppDomain extends Domain {
debuggingOptions: options, debuggingOptions: options,
applicationBinary: applicationBinary, applicationBinary: applicationBinary,
ipv6: ipv6, ipv6: ipv6,
machine: machine,
); );
} }
......
...@@ -450,6 +450,7 @@ class RunCommand extends RunCommandBase { ...@@ -450,6 +450,7 @@ class RunCommand extends RunCommandBase {
packagesFilePath: globalResults['packages'] as String, packagesFilePath: globalResults['packages'] as String,
dillOutputPath: stringArg('output-dill'), dillOutputPath: stringArg('output-dill'),
ipv6: ipv6, ipv6: ipv6,
machine: true,
); );
} on Exception catch (error) { } on Exception catch (error) {
throwToolExit(error.toString()); throwToolExit(error.toString());
......
...@@ -705,6 +705,7 @@ abstract class ResidentRunner { ...@@ -705,6 +705,7 @@ abstract class ResidentRunner {
this.stayResident = true, this.stayResident = true,
this.hotMode = true, this.hotMode = true,
String dillOutputPath, String dillOutputPath,
this.machine = false,
}) : mainPath = findMainDartFile(target), }) : mainPath = findMainDartFile(target),
packagesFilePath = debuggingOptions.buildInfo.packagesPath, packagesFilePath = debuggingOptions.buildInfo.packagesPath,
projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path, projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path,
...@@ -741,6 +742,7 @@ abstract class ResidentRunner { ...@@ -741,6 +742,7 @@ abstract class ResidentRunner {
final AssetBundle assetBundle; final AssetBundle assetBundle;
final CommandHelp commandHelp; final CommandHelp commandHelp;
final bool machine;
io.HttpServer _devtoolsServer; io.HttpServer _devtoolsServer;
...@@ -1141,7 +1143,7 @@ abstract class ResidentRunner { ...@@ -1141,7 +1143,7 @@ abstract class ResidentRunner {
} }
void printStructuredErrorLog(vm_service.Event event) { void printStructuredErrorLog(vm_service.Event event) {
if (event.extensionKind == 'Flutter.Error') { if (event.extensionKind == 'Flutter.Error' && !machine) {
final Map<dynamic, dynamic> json = event.extensionData?.data; final Map<dynamic, dynamic> json = event.extensionData?.data;
if (json != null && json.containsKey('renderedErrorText')) { if (json != null && json.containsKey('renderedErrorText')) {
globals.printStatus('\n${json['renderedErrorText']}'); globals.printStatus('\n${json['renderedErrorText']}');
......
...@@ -23,12 +23,16 @@ class ColdRunner extends ResidentRunner { ...@@ -23,12 +23,16 @@ class ColdRunner extends ResidentRunner {
this.applicationBinary, this.applicationBinary,
bool ipv6 = false, bool ipv6 = false,
bool stayResident = true, bool stayResident = true,
}) : super(devices, bool machine = false,
target: target, }) : super(
debuggingOptions: debuggingOptions, devices,
hotMode: false, target: target,
stayResident: stayResident, debuggingOptions: debuggingOptions,
ipv6: ipv6); hotMode: false,
stayResident: stayResident,
ipv6: ipv6,
machine: machine,
);
final bool traceStartup; final bool traceStartup;
final bool awaitFirstFrameWhenTracing; final bool awaitFirstFrameWhenTracing;
......
...@@ -74,14 +74,18 @@ class HotRunner extends ResidentRunner { ...@@ -74,14 +74,18 @@ class HotRunner extends ResidentRunner {
String dillOutputPath, String dillOutputPath,
bool stayResident = true, bool stayResident = true,
bool ipv6 = false, bool ipv6 = false,
}) : super(devices, bool machine = false,
target: target, }) : super(
debuggingOptions: debuggingOptions, devices,
projectRootPath: projectRootPath, target: target,
stayResident: stayResident, debuggingOptions: debuggingOptions,
hotMode: true, projectRootPath: projectRootPath,
dillOutputPath: dillOutputPath, stayResident: stayResident,
ipv6: ipv6); hotMode: true,
dillOutputPath: dillOutputPath,
ipv6: ipv6,
machine: machine,
);
final bool benchmarkMode; final bool benchmarkMode;
final File applicationBinary; final File applicationBinary;
......
...@@ -25,5 +25,6 @@ abstract class WebRunnerFactory { ...@@ -25,5 +25,6 @@ abstract class WebRunnerFactory {
@required bool ipv6, @required bool ipv6,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
@required UrlTunneller urlTunneller, @required UrlTunneller urlTunneller,
bool machine = false,
}); });
} }
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:process/process.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import '../src/common.dart'; import '../src/common.dart';
import 'test_data/project_with_early_error.dart'; import 'test_data/project_with_early_error.dart';
...@@ -29,38 +34,89 @@ void main() { ...@@ -29,38 +34,89 @@ void main() {
tryToDelete(tempDir); tryToDelete(tempDir);
}); });
test('flutter run reports an early error in an application', () async { test('flutter run in non-machine mode reports an early error in an application', () async {
final String flutterBin = globals.fs.path.join(
getFlutterRoot(),
'bin',
'flutter',
);
final StringBuffer stdout = StringBuffer(); final StringBuffer stdout = StringBuffer();
await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true); final Process process = await const LocalProcessManager().start(<String>[
flutterBin,
'run',
'--disable-service-auth-codes',
'--show-test-device',
'-dflutter-tester',
'--start-paused',
'--dart-define=flutter.inspector.structuredErrors=true',
], workingDirectory: tempDir.path);
transformToLines(process.stdout).listen((String line) async {
stdout.writeln(line);
if (line.startsWith('An Observatory debugger')) {
final RegExp exp = RegExp(r'http://127.0.0.1:(\d+)/');
final RegExpMatch match = exp.firstMatch(line);
final String port = match.group(1);
if (port != null) {
final VmService vmService =
await vmServiceConnectUri('ws://localhost:$port/ws');
final VM vm = await vmService.getVM();
for (final IsolateRef isolate in vm.isolates) {
await vmService.resume(isolate.id);
}
}
}
if (line.startsWith('Another exception was thrown')) {
process.kill();
}
});
await process.exitCode;
expect(stdout.toString(), contains(_exceptionStart));
});
test('flutter run in machine mode does not print an error', () async {
final StringBuffer stdout = StringBuffer();
await _flutter.run(
startPaused: true,
withDebugger: true,
structuredErrors: true,
);
await _flutter.resume(); await _flutter.resume();
final Completer<void> completer = Completer<void>(); final Completer<void> completer = Completer<void>();
bool lineFound = false;
await Future<void>(() async { await Future<void>(() async {
_flutter.stdout.listen((String line) { _flutter.stdout.listen((String line) {
stdout.writeln(line); stdout.writeln(line);
if (line.startsWith('Another exception was thrown') && !lineFound) {
lineFound = true;
completer.complete();
}
}); });
await completer.future; await completer.future;
}).timeout(const Duration(seconds: 15), onTimeout: () { }).timeout(const Duration(seconds: 5), onTimeout: () {
// Complete anyway in case we don't see the 'Another exception' line. // We don't expect to see any output but want to write to stdout anyway.
completer.complete(); completer.complete();
}); });
await _flutter.stop(); await _flutter.stop();
expect(stdout.toString(), contains(_exceptionStart)); expect(stdout.toString(), isNot(contains(_exceptionStart)));
}); });
test('flutter run for web reports an early error in an application', () async { test('flutter run for web reports an early error in an application', () async {
final StringBuffer stdout = StringBuffer(); final StringBuffer stdout = StringBuffer();
await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true, chrome: true); await _flutter.run(
startPaused: true,
withDebugger: true,
structuredErrors: true,
chrome: true,
machine: false,
);
await _flutter.resume(); await _flutter.resume();
final Completer<void> completer = Completer<void>(); final Completer<void> completer = Completer<void>();
......
...@@ -439,6 +439,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { ...@@ -439,6 +439,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool chrome = false, bool chrome = false,
bool expressionEvaluation = true, bool expressionEvaluation = true,
bool structuredErrors = false, bool structuredErrors = false,
bool machine = true,
File pidFile, File pidFile,
String script, String script,
}) async { }) async {
...@@ -447,7 +448,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { ...@@ -447,7 +448,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
'run', 'run',
if (!chrome) if (!chrome)
'--disable-service-auth-codes', '--disable-service-auth-codes',
'--machine', if (machine) '--machine',
'-d', '-d',
if (chrome) if (chrome)
...<String>[ ...<String>[
......
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