mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +00:00
Improve error handling
This commit is contained in:
parent
4f674e82b5
commit
e2eef703a6
1 changed files with 32 additions and 15 deletions
|
|
@ -107,7 +107,7 @@ enum CaptureError: Error, LocalizedError {
|
||||||
case captureCreationFailed
|
case captureCreationFailed
|
||||||
case windowNotFound
|
case windowNotFound
|
||||||
case windowCaptureFailed
|
case windowCaptureFailed
|
||||||
case fileWriteError(String)
|
case fileWriteError(String, Error?)
|
||||||
case appNotFound(String)
|
case appNotFound(String)
|
||||||
case invalidWindowIndex(Int)
|
case invalidWindowIndex(Int)
|
||||||
case invalidArgument(String)
|
case invalidArgument(String)
|
||||||
|
|
@ -116,31 +116,48 @@ enum CaptureError: Error, LocalizedError {
|
||||||
var errorDescription: String? {
|
var errorDescription: String? {
|
||||||
switch self {
|
switch self {
|
||||||
case .noDisplaysAvailable:
|
case .noDisplaysAvailable:
|
||||||
"No displays available for capture."
|
return "No displays available for capture."
|
||||||
case .screenRecordingPermissionDenied:
|
case .screenRecordingPermissionDenied:
|
||||||
"Screen recording permission is required. " +
|
return "Screen recording permission is required. " +
|
||||||
"Please grant it in System Settings > Privacy & Security > Screen Recording."
|
"Please grant it in System Settings > Privacy & Security > Screen Recording."
|
||||||
case .accessibilityPermissionDenied:
|
case .accessibilityPermissionDenied:
|
||||||
"Accessibility permission is required for some operations. " +
|
return "Accessibility permission is required for some operations. " +
|
||||||
"Please grant it in System Settings > Privacy & Security > Accessibility."
|
"Please grant it in System Settings > Privacy & Security > Accessibility."
|
||||||
case .invalidDisplayID:
|
case .invalidDisplayID:
|
||||||
"Invalid display ID provided."
|
return "Invalid display ID provided."
|
||||||
case .captureCreationFailed:
|
case .captureCreationFailed:
|
||||||
"Failed to create the screen capture."
|
return "Failed to create the screen capture."
|
||||||
case .windowNotFound:
|
case .windowNotFound:
|
||||||
"The specified window could not be found."
|
return "The specified window could not be found."
|
||||||
case .windowCaptureFailed:
|
case .windowCaptureFailed:
|
||||||
"Failed to capture the specified window."
|
return "Failed to capture the specified window."
|
||||||
case let .fileWriteError(path):
|
case let .fileWriteError(path, underlyingError):
|
||||||
"Failed to write capture file to path: \(path)."
|
var message = "Failed to write capture file to path: \(path)."
|
||||||
|
|
||||||
|
if let error = underlyingError {
|
||||||
|
let errorString = error.localizedDescription
|
||||||
|
if errorString.lowercased().contains("permission") {
|
||||||
|
message += " Permission denied - check that the directory is writable and the application has necessary permissions."
|
||||||
|
} else if errorString.lowercased().contains("no such file") {
|
||||||
|
message += " Directory does not exist - ensure the parent directory exists."
|
||||||
|
} else if errorString.lowercased().contains("no space") {
|
||||||
|
message += " Insufficient disk space available."
|
||||||
|
} else {
|
||||||
|
message += " \(errorString)"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message += " This may be due to insufficient permissions, missing directory, or disk space issues."
|
||||||
|
}
|
||||||
|
|
||||||
|
return message
|
||||||
case let .appNotFound(identifier):
|
case let .appNotFound(identifier):
|
||||||
"Application with identifier '\(identifier)' not found or is not running."
|
return "Application with identifier '\(identifier)' not found or is not running."
|
||||||
case let .invalidWindowIndex(index):
|
case let .invalidWindowIndex(index):
|
||||||
"Invalid window index: \(index)."
|
return "Invalid window index: \(index)."
|
||||||
case let .invalidArgument(message):
|
case let .invalidArgument(message):
|
||||||
"Invalid argument: \(message)"
|
return "Invalid argument: \(message)"
|
||||||
case let .unknownError(message):
|
case let .unknownError(message):
|
||||||
"An unexpected error occurred: \(message)"
|
return "An unexpected error occurred: \(message)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +170,7 @@ enum CaptureError: Error, LocalizedError {
|
||||||
case .captureCreationFailed: 14
|
case .captureCreationFailed: 14
|
||||||
case .windowNotFound: 15
|
case .windowNotFound: 15
|
||||||
case .windowCaptureFailed: 16
|
case .windowCaptureFailed: 16
|
||||||
case .fileWriteError: 17
|
case .fileWriteError(_, _): 17
|
||||||
case .appNotFound: 18
|
case .appNotFound: 18
|
||||||
case .invalidWindowIndex: 19
|
case .invalidWindowIndex: 19
|
||||||
case .invalidArgument: 20
|
case .invalidArgument: 20
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue