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 6166ca0e62..41bc27e885 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -777,6 +777,7 @@ void _handlePosixException(Exception e, String? message, int errorCode, String? void _handleMacOSException(Exception e, String? message, int errorCode, String? posixPermissionSuggestion) { // https://github.com/apple/darwin-xnu/blob/main/bsd/dev/dtrace/scripts/errno.d const int ebadarch = 86; + const int eagain = 35; if (errorCode == ebadarch) { final StringBuffer errorBuffer = StringBuffer(); if (message != null) { @@ -787,6 +788,17 @@ void _handleMacOSException(Exception e, String? message, int errorCode, String? errorBuffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license'); _throwFileSystemException(errorBuffer.toString()); } + if (errorCode == eagain) { + final StringBuffer errorBuffer = StringBuffer(); + if (message != null) { + errorBuffer.writeln('$message.'); + } + errorBuffer.writeln( + 'Your system may be running into its process limits. ' + 'Consider quitting unused apps and trying again.', + ); + throwToolExit(errorBuffer.toString()); + } _handlePosixException(e, message, errorCode, posixPermissionSuggestion); } 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 bc34665541..a43367c341 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 @@ -1108,6 +1108,7 @@ Please ensure that the SDK and/or project is installed in a location that has re const int enospc = 28; const int eacces = 13; const int ebadarch = 86; + const int eagain = 35; testWithoutContext('when writing to a full device', () { final FakeProcessManager fakeProcessManager = FakeProcessManager.list([ @@ -1190,6 +1191,24 @@ Please ensure that the SDK and/or project is installed in a location that has re expect(() => processManager.runSync(['foo', '--bar']), throwsToolExit(message: expectedMessage)); }); + + testWithoutContext('when up against resource limits (EAGAIN)', () async { + final FakeProcessManager fakeProcessManager = FakeProcessManager.list([ + const FakeCommand(command: ['foo', '--bar'], exception: ProcessException('', [], '', eagain)), + ]); + + final ProcessManager processManager = ErrorHandlingProcessManager( + delegate: fakeProcessManager, + platform: macOSPlatform, + ); + + const String expectedMessage = 'Flutter failed to run "foo --bar".\n' + 'Your system may be running into its process limits. ' + 'Consider quitting unused apps and trying again.'; + + expect(() async => processManager.start(['foo', '--bar']), + throwsToolExit(message: expectedMessage)); + }); }); testWithoutContext('ErrorHandlingProcessManager delegates killPid correctly', () async {