diff --git a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift index bc29e40..cff38cf 100644 --- a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift @@ -60,6 +60,8 @@ struct ImageCommand: AsyncParsableCommand { outputResults(savedFiles) } catch { handleError(error) + // Throw a special exit error that AsyncParsableCommand can handle + throw ExitCode(Int32(1)) } } @@ -98,7 +100,7 @@ struct ImageCommand: AsyncParsableCommand { } } - private func handleError(_ error: Error) -> Never { + private func handleError(_ error: Error) { ImageErrorHandler.handleError(error, jsonOutput: jsonOutput) } diff --git a/peekaboo-cli/Sources/peekaboo/ImageErrorHandler.swift b/peekaboo-cli/Sources/peekaboo/ImageErrorHandler.swift index 0d82891..83041af 100644 --- a/peekaboo-cli/Sources/peekaboo/ImageErrorHandler.swift +++ b/peekaboo-cli/Sources/peekaboo/ImageErrorHandler.swift @@ -2,7 +2,7 @@ import Foundation import AppKit struct ImageErrorHandler { - static func handleError(_ error: Error, jsonOutput: Bool) -> Never { + static func handleError(_ error: Error, jsonOutput: Bool) { let captureError: CaptureError = if let err = error as? CaptureError { err } else { @@ -70,6 +70,6 @@ struct ImageErrorHandler { var localStandardErrorStream = FileHandleTextOutputStream(FileHandle.standardError) print("Error: \(captureError.localizedDescription)", to: &localStandardErrorStream) } - Foundation.exit(captureError.exitCode) + // Don't call exit() here - let the caller handle process termination } } diff --git a/peekaboo-cli/Sources/peekaboo/ListCommand.swift b/peekaboo-cli/Sources/peekaboo/ListCommand.swift index c0dee03..4752482 100644 --- a/peekaboo-cli/Sources/peekaboo/ListCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ListCommand.swift @@ -41,10 +41,11 @@ struct AppsSubcommand: AsyncParsableCommand { } catch { handleError(error) + throw ExitCode(Int32(1)) } } - private func handleError(_ error: Error) -> Never { + private func handleError(_ error: Error) { let captureError: CaptureError = if let err = error as? CaptureError { err } else if let appError = error as? ApplicationError { @@ -75,7 +76,7 @@ struct AppsSubcommand: AsyncParsableCommand { } else { fputs("Error: \(captureError.localizedDescription)\n", stderr) } - Foundation.exit(captureError.exitCode) + // Don't call exit() here - let the caller handle process termination } func printApplicationList(_ applications: [ApplicationInfo]) { @@ -156,10 +157,11 @@ struct WindowsSubcommand: AsyncParsableCommand { } catch { handleError(error) + throw ExitCode(Int32(1)) } } - private func handleError(_ error: Error) -> Never { + private func handleError(_ error: Error) { let captureError: CaptureError = if let err = error as? CaptureError { err } else if let appError = error as? ApplicationError { @@ -192,7 +194,7 @@ struct WindowsSubcommand: AsyncParsableCommand { } else { fputs("Error: \(captureError.localizedDescription)\n", stderr) } - Foundation.exit(captureError.exitCode) + // Don't call exit() here - let the caller handle process termination } private func parseIncludeDetails() -> Set { diff --git a/peekaboo-cli/Sources/peekaboo/ScreenCapture.swift b/peekaboo-cli/Sources/peekaboo/ScreenCapture.swift index a890bc4..d43cf1e 100644 --- a/peekaboo-cli/Sources/peekaboo/ScreenCapture.swift +++ b/peekaboo-cli/Sources/peekaboo/ScreenCapture.swift @@ -1,6 +1,6 @@ import Foundation import CoreGraphics -import ScreenCaptureKit +@preconcurrency import ScreenCaptureKit struct ScreenCapture: Sendable { static func captureDisplay(