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 {
@required bool ipv6,
@required DebuggingOptions debuggingOptions,
@required UrlTunneller urlTunneller,
bool machine = false,
}) {
return _ResidentWebRunner(
device,
......@@ -62,6 +63,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
ipv6: ipv6,
stayResident: stayResident,
urlTunneller: urlTunneller,
machine: machine,
);
}
}
......@@ -79,12 +81,14 @@ abstract class ResidentWebRunner extends ResidentRunner {
@required bool ipv6,
@required DebuggingOptions debuggingOptions,
bool stayResident = true,
bool machine = false,
}) : super(
<FlutterDevice>[device],
target: target ?? globals.fs.path.join('lib', 'main.dart'),
debuggingOptions: debuggingOptions,
ipv6: ipv6,
stayResident: stayResident,
machine: machine,
);
FlutterDevice get device => flutterDevices.first;
......@@ -390,6 +394,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
@required DebuggingOptions debuggingOptions,
bool stayResident = true,
@required this.urlTunneller,
bool machine = false,
}) : super(
device,
flutterProject: flutterProject,
......@@ -397,6 +402,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
debuggingOptions: debuggingOptions,
ipv6: ipv6,
stayResident: stayResident,
machine: machine,
);
final UrlTunneller urlTunneller;
......
......@@ -448,6 +448,7 @@ class AppDomain extends Domain {
String dillOutputPath,
bool ipv6 = false,
String isolateFilter,
bool machine = true,
}) async {
if (!await device.supportsRuntimeMode(options.buildInfo.mode)) {
throw Exception(
......@@ -480,6 +481,7 @@ class AppDomain extends Domain {
ipv6: ipv6,
stayResident: true,
urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null,
machine: machine,
);
} else if (enableHotReload) {
runner = HotRunner(
......@@ -491,6 +493,7 @@ class AppDomain extends Domain {
dillOutputPath: dillOutputPath,
ipv6: ipv6,
hostIsIde: true,
machine: machine,
);
} else {
runner = ColdRunner(
......@@ -499,6 +502,7 @@ class AppDomain extends Domain {
debuggingOptions: options,
applicationBinary: applicationBinary,
ipv6: ipv6,
machine: machine,
);
}
......
......@@ -450,6 +450,7 @@ class RunCommand extends RunCommandBase {
packagesFilePath: globalResults['packages'] as String,
dillOutputPath: stringArg('output-dill'),
ipv6: ipv6,
machine: true,
);
} on Exception catch (error) {
throwToolExit(error.toString());
......
......@@ -705,6 +705,7 @@ abstract class ResidentRunner {
this.stayResident = true,
this.hotMode = true,
String dillOutputPath,
this.machine = false,
}) : mainPath = findMainDartFile(target),
packagesFilePath = debuggingOptions.buildInfo.packagesPath,
projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path,
......@@ -741,6 +742,7 @@ abstract class ResidentRunner {
final AssetBundle assetBundle;
final CommandHelp commandHelp;
final bool machine;
io.HttpServer _devtoolsServer;
......@@ -1141,7 +1143,7 @@ abstract class ResidentRunner {
}
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;
if (json != null && json.containsKey('renderedErrorText')) {
globals.printStatus('\n${json['renderedErrorText']}');
......
......@@ -23,12 +23,16 @@ class ColdRunner extends ResidentRunner {
this.applicationBinary,
bool ipv6 = false,
bool stayResident = true,
}) : super(devices,
target: target,
debuggingOptions: debuggingOptions,
hotMode: false,
stayResident: stayResident,
ipv6: ipv6);
bool machine = false,
}) : super(
devices,
target: target,
debuggingOptions: debuggingOptions,
hotMode: false,
stayResident: stayResident,
ipv6: ipv6,
machine: machine,
);
final bool traceStartup;
final bool awaitFirstFrameWhenTracing;
......
......@@ -74,14 +74,18 @@ class HotRunner extends ResidentRunner {
String dillOutputPath,
bool stayResident = true,
bool ipv6 = false,
}) : super(devices,
target: target,
debuggingOptions: debuggingOptions,
projectRootPath: projectRootPath,
stayResident: stayResident,
hotMode: true,
dillOutputPath: dillOutputPath,
ipv6: ipv6);
bool machine = false,
}) : super(
devices,
target: target,
debuggingOptions: debuggingOptions,
projectRootPath: projectRootPath,
stayResident: stayResident,
hotMode: true,
dillOutputPath: dillOutputPath,
ipv6: ipv6,
machine: machine,
);
final bool benchmarkMode;
final File applicationBinary;
......
......@@ -25,5 +25,6 @@ abstract class WebRunnerFactory {
@required bool ipv6,
@required DebuggingOptions debuggingOptions,
@required UrlTunneller urlTunneller,
bool machine = false,
});
}
......@@ -3,9 +3,14 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:file/file.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 'test_data/project_with_early_error.dart';
......@@ -29,38 +34,89 @@ void main() {
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();
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();
final Completer<void> completer = Completer<void>();
bool lineFound = false;
await Future<void>(() async {
_flutter.stdout.listen((String line) {
stdout.writeln(line);
if (line.startsWith('Another exception was thrown') && !lineFound) {
lineFound = true;
completer.complete();
}
});
await completer.future;
}).timeout(const Duration(seconds: 15), onTimeout: () {
// Complete anyway in case we don't see the 'Another exception' line.
}).timeout(const Duration(seconds: 5), onTimeout: () {
// We don't expect to see any output but want to write to stdout anyway.
completer.complete();
});
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 {
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();
final Completer<void> completer = Completer<void>();
......
......@@ -439,6 +439,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool chrome = false,
bool expressionEvaluation = true,
bool structuredErrors = false,
bool machine = true,
File pidFile,
String script,
}) async {
......@@ -447,7 +448,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
'run',
if (!chrome)
'--disable-service-auth-codes',
'--machine',
if (machine) '--machine',
'-d',
if (chrome)
...<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