Skip to content

Commit 13007e7

Browse files
committed
Catch output-file-map.json write error thrown from TSC
We already had logic to retry loading a package manifest if writing the output-file-map failed. This only covered errors thrown from Foundation but I was seeing similar errors from TSC. Cover those as well.
1 parent 1ca9780 commit 13007e7

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Sources/BuildServerIntegration/SwiftPMBuildServer.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ package import struct BuildServerProtocol.SourceItem
3535
import struct TSCBasic.AbsolutePath
3636
import class TSCBasic.Process
3737
package import class ToolchainRegistry.Toolchain
38+
import struct TSCBasic.FileSystemError
3839

3940
private typealias AbsolutePath = Basics.AbsolutePath
4041

@@ -351,22 +352,36 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
351352
description: "Create SwiftPM build description"
352353
)
353354
)
354-
} catch let error as NSError {
355-
#if os(Windows)
356-
if error.domain == NSCocoaErrorDomain, error.code == CocoaError.fileWriteNoPermission.rawValue,
357-
let url = error.userInfo["NSURL"] as? URL, url.lastPathComponent == "output-file-map.json",
358-
loadAttempt < maxLoadAttempts
355+
} catch {
356+
guard SwiftExtensions.Platform.current == .windows else {
357+
// We only retry loading the build description on Windows. The output-file-map issue does not exist on other
358+
// platforms.
359+
throw error
360+
}
361+
let isOutputFileMapWriteError: Bool
362+
let nsError = error as NSError
363+
if nsError.domain == NSCocoaErrorDomain,
364+
nsError.code == CocoaError.fileWriteNoPermission.rawValue,
365+
(nsError.userInfo["NSURL"] as? URL)?.lastPathComponent == "output-file-map.json"
366+
{
367+
isOutputFileMapWriteError = true
368+
} else if let error = error as? FileSystemError,
369+
error.kind == .invalidAccess && error.path?.basename == "output-file-map.json"
359370
{
371+
isOutputFileMapWriteError = true
372+
} else {
373+
isOutputFileMapWriteError = false
374+
}
375+
if isOutputFileMapWriteError, loadAttempt < maxLoadAttempts {
360376
logger.log(
361377
"""
362378
Loading the build description failed to write output-file-map.json \
363379
(attempt \(loadAttempt)/\(maxLoadAttempts)), trying again.
364-
\(error)
380+
\(error.forLogging)
365381
"""
366382
)
367383
continue
368384
}
369-
#endif
370385
throw error
371386
}
372387
}

0 commit comments

Comments
 (0)