-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSError+UbiquityStoreManager.m
executable file
·81 lines (67 loc) · 3.18 KB
/
NSError+UbiquityStoreManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright Maarten Billemont (http://www.lhunath.com, [email protected])
*
* See the enclosed file LICENSE for license information (LASGPLv3).
*
* @author Maarten Billemont <[email protected]>
* @license Lesser-AppStore General Public License
*/
#import <CoreData/CoreData.h>
#import "NSError+UbiquityStoreManager.h"
NSString *const UbiquityManagedStoreDidDetectCorruptionNotification = @"UbiquityManagedStoreDidDetectCorruptionNotification";
NSString *const USMStoreURLsErrorKey = @"USMStoreURLsErrorKey";
@implementation NSError(UbiquityStoreManager)
- (id)init_USM_WithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict {
self = [self init_USM_WithDomain:domain code:code userInfo:dict];
if ([domain isEqualToString:NSCocoaErrorDomain] && code == 134302) {
if (![self handleError:self]) {
MyLog( @"===" );
MyLog( @"Detected unknown ubiquity import error." );
MyLog( @"Please report this at http://lhunath.github.io/UbiquityStoreManager" );
MyLog( @"and provide details of the conditions and whether or not you notice" );
MyLog( @"any sync issues afterwards. Error userInfo:" );
for (id key in dict) {
id value = dict[key];
MyLog( @"[%@] %@ => [%@] %@", [key class], key, [value class], value );
}
MyLog( @"Error Debug Description:\n%@", [self debugDescription] );
MyLog( @"===" );
}
}
return self;
}
- (BOOL)handleError:(NSError *)error {
if (!error)
return NO;
if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == NSValidationMissingMandatoryPropertyError) {
// Severity: Critical To Cloud Content
// Cause: Validation Error -- non-optional property with a nil value. The other end of a required relationship is missing from the store.
// Action: Mark corrupt, request rebuild.
NSManagedObject *object = [error userInfo][NSValidationObjectErrorKey];
NSPersistentStoreCoordinator *psc = object.managedObjectContext.persistentStoreCoordinator;
NSMutableArray *storeURLs = [NSMutableArray arrayWithCapacity:[psc.persistentStores count]];
for (NSPersistentStore *store in psc.persistentStores)
[storeURLs addObject:[psc URLForPersistentStore:store]];
[[NSNotificationCenter defaultCenter] postNotificationName:UbiquityManagedStoreDidDetectCorruptionNotification object:@{
NSUnderlyingErrorKey : self,
USMStoreURLsErrorKey : storeURLs,
}];
return YES;
}
if ([(NSString *)(error.userInfo)[@"reason"] hasPrefix:@"Error reading the log file at location: (null)"]) {
// Severity: Delayed Import?
// Cause: Log file failed to download?
// Action: Ignore.
return YES;
}
if ([self handleError:(error.userInfo)[NSUnderlyingErrorKey]])
return YES;
if ([self handleError:(error.userInfo)[@"underlyingError"]])
return YES;
NSArray *errors = (error.userInfo)[@"NSDetailedErrors"];
for (NSError *error_ in errors)
if ([self handleError:error_])
return YES;
return NO;
}
@end