From 9fe556705be2a091a3e4286ebbceeff612a41da4 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 17 Feb 2023 14:02:51 -0800 Subject: [PATCH] Print sub process that failed to run in tool (#120999) --- .../lib/src/base/error_handling_io.dart | 23 +++++++++++++----- .../base/error_handling_io_test.dart | 24 +++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/error_handling_io.dart b/packages/flutter_tools/lib/src/base/error_handling_io.dart index 203190d062..044235c1a6 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -667,7 +667,10 @@ class ErrorHandlingProcessManager extends ProcessManager { stdoutEncoding: stdoutEncoding, stderrEncoding: stderrEncoding, ); - }, platform: _platform); + }, + platform: _platform, + failureMessage: 'Flutter failed to run "${command.join(' ')}"', + ); } @override @@ -688,7 +691,10 @@ class ErrorHandlingProcessManager extends ProcessManager { runInShell: runInShell, mode: mode, ); - }, platform: _platform); + }, + platform: _platform, + failureMessage: 'Flutter failed to run "${command.join(' ')}"', + ); } @override @@ -711,7 +717,10 @@ class ErrorHandlingProcessManager extends ProcessManager { stdoutEncoding: stdoutEncoding, stderrEncoding: stderrEncoding, ); - }, platform: _platform); + }, + platform: _platform, + failureMessage: 'Flutter failed to run "${command.join(' ')}"', + ); } } @@ -759,9 +768,11 @@ void _handleMacOSException(Exception e, String? message, int errorCode, String? const int ebadarch = 86; if (errorCode == ebadarch) { final StringBuffer errorBuffer = StringBuffer(); - errorBuffer.writeln(message); - errorBuffer.writeln('This binary was built with the incorrect architecture to run on this machine.'); - errorBuffer.writeln('Flutter requires the Rosetta translation environment. If you are on an ARM Mac, try running:'); + if (message != null) { + errorBuffer.writeln('$message.'); + } + errorBuffer.writeln('The binary was built with the incorrect architecture to run on this machine.'); + errorBuffer.writeln('If you are on an ARM Apple Silicon Mac, Flutter requires the Rosetta translation environment. Try running:'); errorBuffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license'); _throwFileSystemException(errorBuffer.toString()); } diff --git a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart index 4172518d5d..f9fa8ef8d2 100644 --- a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart +++ b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart @@ -963,7 +963,8 @@ void main() { platform: windowsPlatform, ); - const String expectedMessage = 'The flutter tool cannot access the file'; + const String expectedMessage = 'Flutter failed to run "foo". The flutter tool cannot access the file or directory.\n' + 'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.'; expect(() async => processManager.start(['foo']), throwsToolExit(message: expectedMessage)); expect(() async => processManager.run(['foo']), @@ -1021,7 +1022,8 @@ void main() { platform: linuxPlatform, ); - const String expectedMessage = 'The flutter tool cannot access the file'; + const String expectedMessage = 'Flutter failed to run "foo".\n' + 'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.'; expect(() async => processManager.start(['foo']), throwsToolExit(message: expectedMessage)); @@ -1085,7 +1087,8 @@ void main() { platform: macOSPlatform, ); - const String expectedMessage = 'The flutter tool cannot access the file'; + const String expectedMessage = 'Flutter failed to run "foo".\n' + 'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.'; expect(() async => processManager.start(['foo']), throwsToolExit(message: expectedMessage)); @@ -1113,9 +1116,9 @@ void main() { testWithoutContext('when bad CPU type', () async { final FakeProcessManager fakeProcessManager = FakeProcessManager.list([ - const FakeCommand(command: ['foo'], exception: ProcessException('', [], '', ebadarch)), - const FakeCommand(command: ['foo'], exception: ProcessException('', [], '', ebadarch)), - const FakeCommand(command: ['foo'], exception: ProcessException('', [], '', ebadarch)), + const FakeCommand(command: ['foo', '--bar'], exception: ProcessException('', [], '', ebadarch)), + const FakeCommand(command: ['foo', '--bar'], exception: ProcessException('', [], '', ebadarch)), + const FakeCommand(command: ['foo', '--bar'], exception: ProcessException('', [], '', ebadarch)), ]); final ProcessManager processManager = ErrorHandlingProcessManager( @@ -1123,13 +1126,14 @@ void main() { platform: macOSPlatform, ); - const String expectedMessage = 'Flutter requires the Rosetta translation environment'; + const String expectedMessage = 'Flutter failed to run "foo --bar".\n' + 'The binary was built with the incorrect architecture to run on this machine.'; - expect(() async => processManager.start(['foo']), + expect(() async => processManager.start(['foo', '--bar']), throwsToolExit(message: expectedMessage)); - expect(() async => processManager.run(['foo']), + expect(() async => processManager.run(['foo', '--bar']), throwsToolExit(message: expectedMessage)); - expect(() => processManager.runSync(['foo']), + expect(() => processManager.runSync(['foo', '--bar']), throwsToolExit(message: expectedMessage)); }); });