[image-inspect]: stdout/stderr and logging refactor (#1044)

- Relates to #642.
- Each image carries it own error message (allows for different error
types per image)
- Stdout/stderr support
- Use of the new `StderrLogHandler`
This commit is contained in:
Saehej Kang
2026-01-21 22:00:03 -08:00
committed by GitHub
parent a18df81eb0
commit c42108d3df
@@ -16,8 +16,10 @@
import ArgumentParser
import ContainerAPIClient
import ContainerLog
import ContainerizationError
import Foundation
import Logging
import SwiftProtobuf
extension Application {
@@ -34,21 +36,39 @@ extension Application {
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)
}
}
}