Skip to content

Commit f830e4b

Browse files
[flutter_tools] ensure processUtils reports exit code in ProcessExceptions (#136672)
Help to debug situations like: flutter/flutter#135982
1 parent 2c10217 commit f830e4b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class _DefaultProcessUtils implements ProcessUtils {
277277
_logger.printTrace(runResult.toString());
278278
if (throwOnError && runResult.exitCode != 0 &&
279279
(allowedFailures == null || !allowedFailures(runResult.exitCode))) {
280-
runResult.throwException('Process exited abnormally:\n$runResult');
280+
runResult.throwException('Process exited abnormally with exit code ${runResult.exitCode}:\n$runResult');
281281
}
282282
return runResult;
283283
}
@@ -341,7 +341,7 @@ class _DefaultProcessUtils implements ProcessUtils {
341341
_logger.printTrace(runResult.toString());
342342
if (throwOnError && runResult.exitCode != 0 &&
343343
(allowedFailures == null || !allowedFailures(exitCode))) {
344-
runResult.throwException('Process exited abnormally:\n$runResult');
344+
runResult.throwException('Process exited abnormally with exit code $exitCode:\n$runResult');
345345
}
346346
return runResult;
347347
}
@@ -407,7 +407,7 @@ class _DefaultProcessUtils implements ProcessUtils {
407407
}
408408

409409
if (failedExitCode && throwOnError) {
410-
String message = 'The command failed';
410+
String message = 'The command failed with exit code ${runResult.exitCode}';
411411
if (verboseExceptions) {
412412
message = 'The command failed\nStdout:\n${runResult.stdout}\n'
413413
'Stderr:\n${runResult.stderr}';

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ void main() {
3333
exitCode: 1,
3434
));
3535

36-
expect(() async => processUtils.run(<String>['false'], throwOnError: true), throwsProcessException());
36+
expect(
37+
() async => processUtils.run(<String>['false'], throwOnError: true),
38+
throwsProcessException(message: 'Process exited abnormally with exit code 1'),
39+
);
3740
});
3841
});
3942

packages/flutter_tools/test/integration.shard/plist_parser_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void main() {
123123
expect(logger.statusText, contains('Property List error: Unexpected character \x01 at line 1 / '
124124
'JSON error: JSON text did not start with array or object and option to allow fragments not '
125125
'set. around line 1, column 0.\n'));
126-
expect(logger.errorText, 'ProcessException: The command failed\n'
126+
expect(logger.errorText, 'ProcessException: The command failed with exit code 1\n'
127127
' Command: /usr/bin/plutil -convert xml1 -o - ${file.absolute.path}\n');
128128
}, skip: !platform.isMacOS); // [intended] requires macos tool chain.
129129

@@ -185,7 +185,7 @@ void main() {
185185
expect(logger.statusText, contains('foo.plist: Property List error: Unexpected character \x01 '
186186
'at line 1 / JSON error: JSON text did not start with array or object and option to allow '
187187
'fragments not set. around line 1, column 0.\n'));
188-
expect(logger.errorText, equals('ProcessException: The command failed\n'
188+
expect(logger.errorText, equals('ProcessException: The command failed with exit code 1\n'
189189
' Command: /usr/bin/plutil -replace CFBundleIdentifier -string dev.flutter.fake foo.plist\n'));
190190
}, skip: !platform.isMacOS); // [intended] requires macos tool chain.
191191

0 commit comments

Comments
 (0)