From 9cc22f6c43b4662fff6db097662bae67c2fa1e4d Mon Sep 17 00:00:00 2001 From: saehejkang Date: Tue, 13 Jan 2026 02:14:53 -0600 Subject: [PATCH] image-inspect stdout/stderr refactor --- .../Image/ImageInspect.swift | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Sources/ContainerCommands/Image/ImageInspect.swift b/Sources/ContainerCommands/Image/ImageInspect.swift index 785bf486..7e05349b 100644 --- a/Sources/ContainerCommands/Image/ImageInspect.swift +++ b/Sources/ContainerCommands/Image/ImageInspect.swift @@ -16,12 +16,16 @@ import ArgumentParser import ContainerAPIClient +import ContainerLog import ContainerizationError import Foundation +import Logging import SwiftProtobuf extension Application { public struct ImageInspect: AsyncParsableCommand { + public init() {} + public static let configuration = CommandConfiguration( commandName: "inspect", abstract: "Display information about one or more images") @@ -32,23 +36,39 @@ extension Application { @Argument(help: "Images to inspect") var images: [String] - public init() {} + struct InspectError: Error { + let succeeded: [String] + let failed: [(String, Error)] + } public func run() async throws { var printable = [any Codable]() + var succeededImages: [String] = [] + var allErrors: [(String, Error)] = [] + let result = try await ClientImage.get(names: images) - let notFound = result.error + for image in result.images { - guard !Utility.isInfraImage(name: image.reference) else { - continue - } + guard !Utility.isInfraImage(name: image.reference) else { continue } printable.append(try await image.details()) + succeededImages.append(image.reference) } - if printable.count > 0 { + + for missing in result.error { + allErrors.append((missing, ContainerizationError(.notFound, message: "Image not found"))) + } + + if !printable.isEmpty { print(try printable.jsonArray()) } - if notFound.count > 0 { - throw ContainerizationError(.notFound, message: "images: \(notFound.joined(separator: "\n"))") + + if !allErrors.isEmpty { + let logger = Logger(label: "ImageInspect", factory: { _ in StderrLogHandler() }) + for (name, error) in allErrors { + logger.error("\(name): \(error.localizedDescription)") + } + + throw InspectError(succeeded: succeededImages, failed: allErrors) } } }