Unverified Commit a7367b65 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Don't log stack traces to console on build failures (#44966)

parent ff84b3e6
......@@ -226,8 +226,11 @@ class AotBuilder {
status?.stop();
if (!result.success) {
for (ExceptionMeasurement measurement in result.exceptions.values) {
printError(measurement.exception.toString());
printError(measurement.stackTrace.toString());
printError('Target ${measurement.target} failed: ${measurement.exception}',
stackTrace: measurement.fatal
? measurement.stackTrace
: null,
);
}
throwToolExit('Failed to build aot.');
}
......
......@@ -556,6 +556,8 @@ class _BuildInstance {
}
}
} catch (exception, stackTrace) {
// TODO(jonahwilliams): throw specific exception for expected errors to mark
// as non-fatal. All others should be fatal.
node.target.clearStamp(environment);
passed = false;
skipped = false;
......@@ -573,12 +575,15 @@ class _BuildInstance {
/// Helper class to collect exceptions.
class ExceptionMeasurement {
ExceptionMeasurement(this.target, this.exception, this.stackTrace);
ExceptionMeasurement(this.target, this.exception, this.stackTrace, {this.fatal = false});
final String target;
final dynamic exception;
final StackTrace stackTrace;
/// Whether this exception was a fatal build system error.
final bool fatal;
@override
String toString() => 'target: $target\nexception:$exception\n$stackTrace';
}
......
......@@ -126,8 +126,11 @@ Future<void> buildWithAssemble({
if (!result.success) {
for (ExceptionMeasurement measurement in result.exceptions.values) {
printError(measurement.exception.toString());
printError(measurement.stackTrace.toString());
printError('Target ${measurement.target} failed: ${measurement.exception}',
stackTrace: measurement.fatal
? measurement.stackTrace
: null,
);
}
throwToolExit('Failed to build bundle.');
}
......
......@@ -155,8 +155,12 @@ class AssembleCommand extends FlutterCommand {
resourcePoolSize: argResults['resource-pool-size'],
));
if (!result.success) {
for (MapEntry<String, ExceptionMeasurement> data in result.exceptions.entries) {
printError('Target ${data.key} failed: ${data.value.exception}', stackTrace: data.value.stackTrace);
for (ExceptionMeasurement measurement in result.exceptions.values) {
printError('Target ${measurement.target} failed: ${measurement.exception}',
stackTrace: measurement.fatal
? measurement.stackTrace
: null,
);
}
throwToolExit('build failed.');
}
......
......@@ -54,8 +54,11 @@ Future<void> buildWeb(
));
if (!result.success) {
for (ExceptionMeasurement measurement in result.exceptions.values) {
printError(measurement.stackTrace.toString());
printError(measurement.exception.toString());
printError('Target ${measurement.target} failed: ${measurement.exception}',
stackTrace: measurement.fatal
? measurement.stackTrace
: null,
);
}
throwToolExit('Failed to compile application for the Web.');
}
......
......@@ -41,7 +41,8 @@ void main() {
});
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
expect(commandRunner.run(<String>['assemble', 'debug_macos_bundle_flutter_assets']), throwsA(isInstanceOf<ToolExit>()));
expect(commandRunner.run(<String>['assemble', 'debug_macos_bundle_flutter_assets']),
throwsA(isInstanceOf<ToolExit>()));
});
testbed.test('Throws ToolExit if called with non-existent rule', () async {
......@@ -51,7 +52,25 @@ void main() {
});
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
expect(commandRunner.run(<String>['assemble', '-o Output', 'undefined']), throwsA(isInstanceOf<ToolExit>()));
expect(commandRunner.run(<String>['assemble', '-o Output', 'undefined']),
throwsA(isInstanceOf<ToolExit>()));
});
testbed.test('Does not log stack traces during build failure', () async {
final BufferLogger bufferLogger = logger;
final StackTrace testStackTrace = StackTrace.current;
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
.thenAnswer((Invocation invocation) async {
return BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', testStackTrace),
});
});
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
await expectLater(commandRunner.run(<String>['assemble', '-o Output', 'debug_macos_bundle_flutter_assets']),
throwsA(isInstanceOf<ToolExit>()));
expect(bufferLogger.errorText, contains('bar'));
expect(bufferLogger.errorText, isNot(contains(testStackTrace.toString())));
});
testbed.test('Only writes input and output files when the values change', () async {
......@@ -65,7 +84,13 @@ void main() {
});
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
await commandRunner.run(<String>['assemble', '-o Output', '--build-outputs=outputs', '--build-inputs=inputs', 'debug_macos_bundle_flutter_assets']);
await commandRunner.run(<String>[
'assemble',
'-o Output',
'--build-outputs=outputs',
'--build-inputs=inputs',
'debug_macos_bundle_flutter_assets',
]);
final File inputs = fs.file('inputs');
final File outputs = fs.file('outputs');
......@@ -75,7 +100,13 @@ void main() {
final DateTime theDistantPast = DateTime(1991, 8, 23);
inputs.setLastModifiedSync(theDistantPast);
outputs.setLastModifiedSync(theDistantPast);
await commandRunner.run(<String>['assemble', '-o Output', '--build-outputs=outputs', '--build-inputs=inputs', 'debug_macos_bundle_flutter_assets']);
await commandRunner.run(<String>[
'assemble',
'-o Output',
'--build-outputs=outputs',
'--build-inputs=inputs',
'debug_macos_bundle_flutter_assets',
]);
expect(inputs.lastModifiedSync(), theDistantPast);
expect(outputs.lastModifiedSync(), theDistantPast);
......@@ -87,7 +118,13 @@ void main() {
inputFiles: <File>[fs.file('foo'), fs.file('fizz')..createSync()],
outputFiles: <File>[fs.file('bar'), fs.file(fs.path.join('.dart_tool', 'fizz2'))..createSync(recursive: true)]);
});
await commandRunner.run(<String>['assemble', '-o Output', '--build-outputs=outputs', '--build-inputs=inputs', 'debug_macos_bundle_flutter_assets']);
await commandRunner.run(<String>[
'assemble',
'-o Output',
'--build-outputs=outputs',
'--build-inputs=inputs',
'debug_macos_bundle_flutter_assets',
]);
expect(inputs.readAsStringSync(), contains('foo'));
expect(inputs.readAsStringSync(), contains('fizz'));
......
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