Unverified Commit f830e4be authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] ensure processUtils reports exit code in ProcessExceptions (#136672)

Help to debug situations like: https://github.com/flutter/flutter/issues/135982
parent 2c102175
...@@ -277,7 +277,7 @@ class _DefaultProcessUtils implements ProcessUtils { ...@@ -277,7 +277,7 @@ class _DefaultProcessUtils implements ProcessUtils {
_logger.printTrace(runResult.toString()); _logger.printTrace(runResult.toString());
if (throwOnError && runResult.exitCode != 0 && if (throwOnError && runResult.exitCode != 0 &&
(allowedFailures == null || !allowedFailures(runResult.exitCode))) { (allowedFailures == null || !allowedFailures(runResult.exitCode))) {
runResult.throwException('Process exited abnormally:\n$runResult'); runResult.throwException('Process exited abnormally with exit code ${runResult.exitCode}:\n$runResult');
} }
return runResult; return runResult;
} }
...@@ -341,7 +341,7 @@ class _DefaultProcessUtils implements ProcessUtils { ...@@ -341,7 +341,7 @@ class _DefaultProcessUtils implements ProcessUtils {
_logger.printTrace(runResult.toString()); _logger.printTrace(runResult.toString());
if (throwOnError && runResult.exitCode != 0 && if (throwOnError && runResult.exitCode != 0 &&
(allowedFailures == null || !allowedFailures(exitCode))) { (allowedFailures == null || !allowedFailures(exitCode))) {
runResult.throwException('Process exited abnormally:\n$runResult'); runResult.throwException('Process exited abnormally with exit code $exitCode:\n$runResult');
} }
return runResult; return runResult;
} }
...@@ -407,7 +407,7 @@ class _DefaultProcessUtils implements ProcessUtils { ...@@ -407,7 +407,7 @@ class _DefaultProcessUtils implements ProcessUtils {
} }
if (failedExitCode && throwOnError) { if (failedExitCode && throwOnError) {
String message = 'The command failed'; String message = 'The command failed with exit code ${runResult.exitCode}';
if (verboseExceptions) { if (verboseExceptions) {
message = 'The command failed\nStdout:\n${runResult.stdout}\n' message = 'The command failed\nStdout:\n${runResult.stdout}\n'
'Stderr:\n${runResult.stderr}'; 'Stderr:\n${runResult.stderr}';
......
...@@ -33,7 +33,10 @@ void main() { ...@@ -33,7 +33,10 @@ void main() {
exitCode: 1, exitCode: 1,
)); ));
expect(() async => processUtils.run(<String>['false'], throwOnError: true), throwsProcessException()); expect(
() async => processUtils.run(<String>['false'], throwOnError: true),
throwsProcessException(message: 'Process exited abnormally with exit code 1'),
);
}); });
}); });
......
...@@ -123,7 +123,7 @@ void main() { ...@@ -123,7 +123,7 @@ void main() {
expect(logger.statusText, contains('Property List error: Unexpected character \x01 at line 1 / ' expect(logger.statusText, contains('Property List error: Unexpected character \x01 at line 1 / '
'JSON error: JSON text did not start with array or object and option to allow fragments not ' 'JSON error: JSON text did not start with array or object and option to allow fragments not '
'set. around line 1, column 0.\n')); 'set. around line 1, column 0.\n'));
expect(logger.errorText, 'ProcessException: The command failed\n' expect(logger.errorText, 'ProcessException: The command failed with exit code 1\n'
' Command: /usr/bin/plutil -convert xml1 -o - ${file.absolute.path}\n'); ' Command: /usr/bin/plutil -convert xml1 -o - ${file.absolute.path}\n');
}, skip: !platform.isMacOS); // [intended] requires macos tool chain. }, skip: !platform.isMacOS); // [intended] requires macos tool chain.
...@@ -185,7 +185,7 @@ void main() { ...@@ -185,7 +185,7 @@ void main() {
expect(logger.statusText, contains('foo.plist: Property List error: Unexpected character \x01 ' expect(logger.statusText, contains('foo.plist: Property List error: Unexpected character \x01 '
'at line 1 / JSON error: JSON text did not start with array or object and option to allow ' 'at line 1 / JSON error: JSON text did not start with array or object and option to allow '
'fragments not set. around line 1, column 0.\n')); 'fragments not set. around line 1, column 0.\n'));
expect(logger.errorText, equals('ProcessException: The command failed\n' expect(logger.errorText, equals('ProcessException: The command failed with exit code 1\n'
' Command: /usr/bin/plutil -replace CFBundleIdentifier -string dev.flutter.fake foo.plist\n')); ' Command: /usr/bin/plutil -replace CFBundleIdentifier -string dev.flutter.fake foo.plist\n'));
}, skip: !platform.isMacOS); // [intended] requires macos tool chain. }, skip: !platform.isMacOS); // [intended] requires macos tool chain.
......
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