Fix Sendable warning in AppleMailError by dropping the NSDictionary payload
appleScriptError carried the raw NSDictionary from NSAppleScript's error out-param, which isn't Sendable and got flagged once the type crossed an async boundary. Extract just the two fields actually used (errorNumber, errorMessage) into plain Int/String instead.
This commit is contained in:
@@ -37,9 +37,9 @@ struct MailSearchResult: Sendable, Equatable {
|
||||
let attachmentCount: String
|
||||
}
|
||||
|
||||
enum AppleMailError: Error {
|
||||
enum AppleMailError: Error, Sendable {
|
||||
case scriptNotCompiled
|
||||
case appleScriptError(NSDictionary)
|
||||
case appleScriptError(number: Int, message: String)
|
||||
}
|
||||
|
||||
@Observable
|
||||
@@ -320,7 +320,9 @@ final class AppleMailService {
|
||||
var errorDict: NSDictionary?
|
||||
let result = script.executeAppleEvent(event, error: &errorDict)
|
||||
if let errorDict {
|
||||
continuation.resume(returning: .failure(.appleScriptError(errorDict)))
|
||||
let number = (errorDict[NSAppleScript.errorNumber] as? Int) ?? 0
|
||||
let message = (errorDict[NSAppleScript.errorMessage] as? String) ?? "Unknown error"
|
||||
continuation.resume(returning: .failure(.appleScriptError(number: number, message: message)))
|
||||
} else {
|
||||
continuation.resume(returning: .success(result))
|
||||
}
|
||||
@@ -358,9 +360,7 @@ final class AppleMailService {
|
||||
return results
|
||||
}
|
||||
|
||||
nonisolated static func mapAppleScriptError(_ errorInfo: NSDictionary) -> String {
|
||||
let number = (errorInfo[NSAppleScript.errorNumber] as? Int) ?? 0
|
||||
let message = (errorInfo[NSAppleScript.errorMessage] as? String) ?? "Unknown error"
|
||||
nonisolated static func mapAppleScriptError(number: Int, message: String) -> String {
|
||||
switch number {
|
||||
case -1743:
|
||||
return "Confab is not authorized to control Mail.app. Grant access in System Settings \u{2192} Privacy & Security \u{2192} Automation \u{2192} Confab \u{2192} Mail, then try again."
|
||||
@@ -375,8 +375,8 @@ final class AppleMailService {
|
||||
switch error {
|
||||
case .scriptNotCompiled:
|
||||
return ["error": "Mail integration failed to initialize (AppleScript compile error)."]
|
||||
case .appleScriptError(let dict):
|
||||
return ["error": mapAppleScriptError(dict)]
|
||||
case .appleScriptError(let number, let message):
|
||||
return ["error": mapAppleScriptError(number: number, message: message)]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,8 +629,8 @@ final class AppleMailService {
|
||||
switch error {
|
||||
case .scriptNotCompiled:
|
||||
message = "Mail integration failed to initialize (AppleScript compile error)."
|
||||
case .appleScriptError(let dict):
|
||||
message = Self.mapAppleScriptError(dict)
|
||||
case .appleScriptError(let number, let msg):
|
||||
message = Self.mapAppleScriptError(number: number, message: msg)
|
||||
}
|
||||
return .failure(NSError(domain: "AppleMailService", code: 1, userInfo: [NSLocalizedDescriptionKey: message]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user