Skip to content

Commit 9fe5567

Browse files
authored
Print sub process that failed to run in tool (#120999)
1 parent f785136 commit 9fe5567

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

packages/flutter_tools/lib/src/base/error_handling_io.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,10 @@ class ErrorHandlingProcessManager extends ProcessManager {
667667
stdoutEncoding: stdoutEncoding,
668668
stderrEncoding: stderrEncoding,
669669
);
670-
}, platform: _platform);
670+
},
671+
platform: _platform,
672+
failureMessage: 'Flutter failed to run "${command.join(' ')}"',
673+
);
671674
}
672675

673676
@override
@@ -688,7 +691,10 @@ class ErrorHandlingProcessManager extends ProcessManager {
688691
runInShell: runInShell,
689692
mode: mode,
690693
);
691-
}, platform: _platform);
694+
},
695+
platform: _platform,
696+
failureMessage: 'Flutter failed to run "${command.join(' ')}"',
697+
);
692698
}
693699

694700
@override
@@ -711,7 +717,10 @@ class ErrorHandlingProcessManager extends ProcessManager {
711717
stdoutEncoding: stdoutEncoding,
712718
stderrEncoding: stderrEncoding,
713719
);
714-
}, platform: _platform);
720+
},
721+
platform: _platform,
722+
failureMessage: 'Flutter failed to run "${command.join(' ')}"',
723+
);
715724
}
716725
}
717726

@@ -759,9 +768,11 @@ void _handleMacOSException(Exception e, String? message, int errorCode, String?
759768
const int ebadarch = 86;
760769
if (errorCode == ebadarch) {
761770
final StringBuffer errorBuffer = StringBuffer();
762-
errorBuffer.writeln(message);
763-
errorBuffer.writeln('This binary was built with the incorrect architecture to run on this machine.');
764-
errorBuffer.writeln('Flutter requires the Rosetta translation environment. If you are on an ARM Mac, try running:');
771+
if (message != null) {
772+
errorBuffer.writeln('$message.');
773+
}
774+
errorBuffer.writeln('The binary was built with the incorrect architecture to run on this machine.');
775+
errorBuffer.writeln('If you are on an ARM Apple Silicon Mac, Flutter requires the Rosetta translation environment. Try running:');
765776
errorBuffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license');
766777
_throwFileSystemException(errorBuffer.toString());
767778
}

packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,8 @@ void main() {
963963
platform: windowsPlatform,
964964
);
965965

966-
const String expectedMessage = 'The flutter tool cannot access the file';
966+
const String expectedMessage = 'Flutter failed to run "foo". The flutter tool cannot access the file or directory.\n'
967+
'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.';
967968
expect(() async => processManager.start(<String>['foo']),
968969
throwsToolExit(message: expectedMessage));
969970
expect(() async => processManager.run(<String>['foo']),
@@ -1021,7 +1022,8 @@ void main() {
10211022
platform: linuxPlatform,
10221023
);
10231024

1024-
const String expectedMessage = 'The flutter tool cannot access the file';
1025+
const String expectedMessage = 'Flutter failed to run "foo".\n'
1026+
'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.';
10251027

10261028
expect(() async => processManager.start(<String>['foo']),
10271029
throwsToolExit(message: expectedMessage));
@@ -1085,7 +1087,8 @@ void main() {
10851087
platform: macOSPlatform,
10861088
);
10871089

1088-
const String expectedMessage = 'The flutter tool cannot access the file';
1090+
const String expectedMessage = 'Flutter failed to run "foo".\n'
1091+
'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.';
10891092

10901093
expect(() async => processManager.start(<String>['foo']),
10911094
throwsToolExit(message: expectedMessage));
@@ -1113,23 +1116,24 @@ void main() {
11131116

11141117
testWithoutContext('when bad CPU type', () async {
11151118
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
1116-
const FakeCommand(command: <String>['foo'], exception: ProcessException('', <String>[], '', ebadarch)),
1117-
const FakeCommand(command: <String>['foo'], exception: ProcessException('', <String>[], '', ebadarch)),
1118-
const FakeCommand(command: <String>['foo'], exception: ProcessException('', <String>[], '', ebadarch)),
1119+
const FakeCommand(command: <String>['foo', '--bar'], exception: ProcessException('', <String>[], '', ebadarch)),
1120+
const FakeCommand(command: <String>['foo', '--bar'], exception: ProcessException('', <String>[], '', ebadarch)),
1121+
const FakeCommand(command: <String>['foo', '--bar'], exception: ProcessException('', <String>[], '', ebadarch)),
11191122
]);
11201123

11211124
final ProcessManager processManager = ErrorHandlingProcessManager(
11221125
delegate: fakeProcessManager,
11231126
platform: macOSPlatform,
11241127
);
11251128

1126-
const String expectedMessage = 'Flutter requires the Rosetta translation environment';
1129+
const String expectedMessage = 'Flutter failed to run "foo --bar".\n'
1130+
'The binary was built with the incorrect architecture to run on this machine.';
11271131

1128-
expect(() async => processManager.start(<String>['foo']),
1132+
expect(() async => processManager.start(<String>['foo', '--bar']),
11291133
throwsToolExit(message: expectedMessage));
1130-
expect(() async => processManager.run(<String>['foo']),
1134+
expect(() async => processManager.run(<String>['foo', '--bar']),
11311135
throwsToolExit(message: expectedMessage));
1132-
expect(() => processManager.runSync(<String>['foo']),
1136+
expect(() => processManager.runSync(<String>['foo', '--bar']),
11331137
throwsToolExit(message: expectedMessage));
11341138
});
11351139
});

0 commit comments

Comments
 (0)