Skip to content

[tool_crash] PathNotFoundException deleting temporary directory in buildXcodeProject on macOS #195906

Description

@bkonyi

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:

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/ios/mac.dart#L612-L614

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)

Related Issues & PRs

Activity

  1. added
    c: crashStack traces logged to the console
    P1High-priority issues at the top of the work list
    team-toolOwned by Flutter Tool team
    toolAffects the "flutter" command-line tool. See also t: labels.
    triaged-toolTriaged by Flutter Tool team
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listc: crashStack traces logged to the consolefound in release: 3.47Found to occur in 3.47t: top-crasherteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions