swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.56k stars 231 forks source link

New errors associated with the use of `--parallel` since updating Xcode #528

Open michaellenaghan opened 1 year ago

michaellenaghan commented 1 year ago

Since updating to Xcode 14.3 — I think that's right, but I'm not sure — I've been seeing a flood of errors whenever I use --parallel. Here's a sampling of the error messages:

...
<unknown>: error: Unable to read configuration: The operation couldn\U2019t be completed. (NSCocoaErrorDomain error 256.)
<unknown>: error: Unable to read configuration: The operation couldn\U2019t be completed. (NSCocoaErrorDomain error 256.)
<unknown>: error: Unable to read configuration: The operation couldn\U2019t be completed. (NSCocoaErrorDomain error 256.)
<unknown>: error: Unable to open NAAStore/Sources/NAAStoreModelAdapter/_Support/TaskSelectionDefinitionInfo+TaskSelectionDefinitionModel.swift: file is not readable or does not exist
<unknown>: error: Unable to open NAAStore/Sources/NAAStoreModelAdapter/_Support/EventInfo+EventModel.swift: file is not readable or does not exist
...

As you can see, most errors mention the config file, but some mention other files. Those other files do in fact exist:

$  ls -al "NAAStore/Sources/NAAStoreModelAdapter/_Support/TaskSelectionDefinitionInfo+TaskSelectionDefinitionModel.swift"
-rw-r--r--  1 me  staff  1707  6 Feb 15:16 NAAStore/Sources/NAAStoreModelAdapter/_Support/TaskSelectionDefinitionInfo+TaskSelectionDefinitionModel.swift
$ ls -al "NAAStore/Sources/NAAStoreModelAdapter/_Support/EventInfo+EventModel.swift"
-rw-r--r--  1 me  staff  751  6 Feb 15:16 NAAStore/Sources/NAAStoreModelAdapter/_Support/EventInfo+EventModel.swift

This command line produces the errors:

swift-format format --configuration ./swift-format.json --in-place --recursive --parallel .

This one does not:

swift-format format --configuration ./swift-format.json --in-place --recursive .

This morning I upgraded swift-format from 508.0.0 to 508.0.1 and I still see the errors.

michaellenaghan commented 1 year ago

I found an explanation in a closed bug, #421. In --parallel mode swift-format opens a lot of files all at once — and blows past the default maxfiles limit of 256.

Using something like:

ulimit -Sn 4096

in the session "fixes" the problem — until you exit the session (or reboot).

A fix that survives reboot is... more involved.

ahoppen commented 7 months ago

Tracked in Apple’s issue tracker as rdar://126948350

ghugues commented 1 week ago

Hello, Is there a workaround for this ? Right now this makes the --parallel option unusable on large projects, which kind of defeats its purpose.

michaellenaghan commented 1 week ago

@ghugues I wrap swift-format in a bash script. This is what the bash script does:

# `--parallel` opens more files than the default `ulimit` allows.
ulimit -Sn 1024 && swift-format format --configuration ./swift-format.json --in-place --parallel --recursive .