Skip to content

Commit 6144b5f

Browse files
committed
Throw error FileManager.default.createFile if returns false
Returning `false` indicates that file creation failed, which we should note instead of ignoring it. This fixes a warning on Linux that the result of `createFile` was ignored.
1 parent 970b44d commit 6144b5f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ package struct DiagnoseCommand: AsyncParsableCommand {
213213
#if os(macOS)
214214
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log messages")
215215
let outputFileUrl = bundlePath.appendingPathComponent("log.txt")
216-
FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil)
216+
guard FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil) else {
217+
throw ReductionError("Failed to create log.txt")
218+
}
217219
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
218220
var bytesCollected = 0
219221
// 50 MB is an average log size collected by sourcekit-lsp diagnose.
@@ -304,7 +306,9 @@ package struct DiagnoseCommand: AsyncParsableCommand {
304306
@MainActor
305307
private func addSwiftVersion(toBundle bundlePath: URL) async throws {
306308
let outputFileUrl = bundlePath.appendingPathComponent("swift-versions.txt")
307-
FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil)
309+
guard FileManager.default.createFile(atPath: outputFileUrl.path, contents: nil) else {
310+
throw ReductionError("Failed to create file at \(outputFileUrl)")
311+
}
308312
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
309313

310314
let toolchains = try await toolchainRegistry.toolchains

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ package actor SkipUnless {
471471
.appending(component: "swift-frontend")
472472
return try await withTestScratchDir { scratchDirectory in
473473
let input = scratchDirectory.appending(component: "Input.swift")
474-
FileManager.default.createFile(atPath: input.pathString, contents: nil)
474+
guard FileManager.default.createFile(atPath: input.pathString, contents: nil) else {
475+
struct FailedToCrateInputFileError: Error {}
476+
throw FailedToCrateInputFileError()
477+
}
475478
// If we can't compile for wasm, this fails complaining that it can't find the stdlib for wasm.
476479
let process = Process(
477480
args: swiftFrontend.pathString,

0 commit comments

Comments
 (0)