Skip to content

Commit

Permalink
Merge 'origin/trunk' into ensure-network-monitor-update-handler-is-ca…
Browse files Browse the repository at this point in the history
…lled-on-start
  • Loading branch information
mokagio committed Mar 18, 2022
2 parents d607bdc + 21ded8d commit 528e9a5
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions Sources/Model/ObjC/Common/Core Data/TracksContextManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,17 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
NSURL *storeURL = [self storeURL];
NSError *error = nil;
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

// Delete the store and try again
[[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
TracksLogError(@"Unresolved error %@, %@", error, [error userInfo]);

if (self.shouldThrowUponFatalCondition) {
@throw [NSException exceptionWithName:TracksPersistentStoreException
reason:[NSString stringWithFormat:@"Error initializing Tracks: %@", error]
userInfo:error.userInfo];
} else {
abort();
}

@throw [NSException exceptionWithName:TracksPersistentStoreException
reason:[NSString stringWithFormat:@"Error initializing Tracks: %@", error]
userInfo:error.userInfo];
}
}

Expand All @@ -88,30 +84,21 @@ - (NSURL *)applicationSupportURLForAppWithBundleIdentifier:(NSString *)bundleIde
withIntermediateDirectories:true
attributes:nil
error:&error];

// It seems safe not to handle this error because Application Support should always be
// available and one should always be able to create a folder in it
if (error != nil) {
TracksLogError(@"Failed to create folder for %@ in Application Support: %@, %@", bundleIdentifier, error, [error userInfo]);

if (self.shouldThrowUponFatalCondition) {
@throw [NSException exceptionWithName:TracksApplicationSupportException
reason:[NSString stringWithFormat:@"Error creating the ApplicationSupport Folder: %@", error]
userInfo:error.userInfo];
} else {
abort();
}

@throw [NSException exceptionWithName:TracksApplicationSupportException
reason:[NSString stringWithFormat:@"Error creating the ApplicationSupport Folder: %@", error]
userInfo:error.userInfo];

}

return folder;
}

- (BOOL)shouldThrowUponFatalCondition {
// We consider it safe to Throw (whenever a Fatal Condition arises) whenever there is no global
// NSException handler set
return NSGetUncaughtExceptionHandler() == nil;
}

// Application Support contains "the files that your app creates and manages on behalf of the user
// and can include files that contain user data".
//
Expand Down

0 comments on commit 528e9a5

Please sign in to comment.