3 let CuttlefishErrorDomain = "CuttlefishError"
4 enum CuttlefishErrorCode: Int {
5 case establishFailed = 1001
6 case invalidChangeToken = 1005
7 case resultGraphNotFullyReachable = 1007
8 case changeTokenExpired = 1018
9 case transactionalFailure = 1019
10 case retryableServerFailure = 1021
11 case keyHierarchyAlreadyExists = 1033
14 struct CuttlefishErrorMatcher {
15 let code: CuttlefishErrorCode
18 // Use a 'pattern match operator' to make pretty case statements matching Cuttlefish errors
19 func ~=(pattern: CuttlefishErrorMatcher, value: Error?) -> Bool {
20 guard let value = value else {
24 let error = value as NSError
26 guard let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError else {
30 return error.domain == CKInternalErrorDomain && error.code == CKInternalErrorCode.errorInternalPluginError.rawValue &&
31 underlyingError.domain == CuttlefishErrorDomain && underlyingError.code == pattern.code.rawValue