Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Sources/ContainerCommands/Image/ImageLoad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension Application {
}

// Read from stdin; otherwise read from the input file
if input == nil {
guard let input else {
Comment thread
saehejkang marked this conversation as resolved.
Outdated
guard FileManager.default.createFile(atPath: tempFile.path(), contents: nil) else {
throw ContainerizationError(.internalError, message: "unable to create temporary file")
}
Expand All @@ -65,11 +65,12 @@ extension Application {
fileHandle.write(chunk)
}
try fileHandle.close()
} else {
guard FileManager.default.fileExists(atPath: input!) else {
print("File does not exist \(input!)")
Application.exit(withError: ArgumentParser.ExitCode(1))
}
return
}

guard FileManager.default.fileExists(atPath: input) else {
log.error("file does not exist", metadata: ["path": "\(input)"])
Application.exit(withError: ArgumentParser.ExitCode(1))
}

let progressConfig = try ProgressConfig(
Expand All @@ -85,7 +86,7 @@ extension Application {

progress.set(description: "Loading tar archive")
let result = try await ClientImage.load(
from: input ?? tempFile.path(),
from: input,
force: force)
if !result.rejectedMembers.isEmpty {
log.warning("archive contains invalid members", metadata: ["paths": "\(result.rejectedMembers)"])
Expand Down
9 changes: 9 additions & 0 deletions Tests/CLITests/Subcommands/Images/TestCLIImagesCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,13 @@ class TestCLIImagesCommand: CLITest {
#expect(status != 0, "Expected non-zero exit for missing image")
#expect(error.contains("image not found"))
}

@Test func testImageLoadMissingFileErrorToStderr() throws {
let missingPath = "/path/that/does/not/exist-\(UUID().uuidString)"
let (_, stdout, stderr, status) = try run(arguments: ["image", "load", "-i", missingPath])

#expect(status != 0, "Expected non-zero exit for missing file")
#expect(stdout.isEmpty, "Expected stdout to be empty, got: \(stdout)")
#expect(stderr.contains("File does not exist \(missingPath)"), "Expected stderr to contain error message, got: \(stderr)")
}
}
Loading