Repository navigation
Description
In Flutter 3.47.8 (58 crashes across 50 unique clients, 100% on macOS), flutter build ios crashes in the finally block of buildXcodeProject (packages/flutter_tools/lib/src/ios/mac.dart) with an unhandled PathNotFoundException (OS Error: No such file or directory, errno = 2) when deleting the temporary build directory /var/folders/.../flutter_ios_build_temp_dir....
In packages/flutter_tools/lib/src/ios/mac.dart, the finally block calls tempDir.deleteSync(recursive: true) unconditionally:
Because ErrorHandlingDirectory.deleteSync (packages/flutter_tools/lib/src/base/error_handling_io.dart) passes ignoreErrorCodes: <int>[kSystemCodeCannotFindFile, kWindowsSystemCodeCannotFindPath] to _runSync, _runSync rethrows ENOENT (errno = 2) instead of converting it to a ToolExit. If the temporary directory under /var/folders has already been removed during the build, tempDir.deleteSync(recursive: true) throws an unhandled PathNotFoundException.
Replacing tempDir.deleteSync(recursive: true) with ErrorHandlingFileSystem.deleteIfExists(tempDir, recursive: true) in buildXcodeProject avoids crashing when the temporary directory is already gone.
Sample Crash Report
Command: flutter build ios --profile --flavor internal
Error:
PathNotFoundException: Deletion failed, path = '/var/folders/8g/qpsdk56d5ysfw7wc7nkmvzqw0000gn/T/flutter_tools.dRhp3J/flutter_ios_build_temp_dir0tICh9' (OS Error: No such file or directory, errno = 2)
Stack Trace:
#0 _Directory._deleteSync (dart:io/directory_impl.dart:216)
#1 FileSystemEntity.deleteSync (dart:io/file_system_entity.dart:425)
#2 ForwardingFileSystemEntity.deleteSync (package:file/src/forwarding/forwarding_file_system_entity.dart:70)
#3 ErrorHandlingDirectory.deleteSync.<anonymous closure> (package:flutter_tools/src/base/error_handling_io.dart:717)
#4 _runSync (package:flutter_tools/src/base/error_handling_io.dart:1118)
#5 ErrorHandlingDirectory.deleteSync (package:flutter_tools/src/base/error_handling_io.dart:716)
#6 buildXcodeProject (package:flutter_tools/src/ios/mac.dart:624)
#7 _BuildIOSSubCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:986)
Activity
[flutter_tools] Use `ErrorHandlingFileSystem.deleteIfExists` for `IOS…