Skip to content

Remove all usages of BFTask.exception APIs. #956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Parse/Internal/BFTask+Private.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,13 @@ - (BFTask *)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
return [self continueWithExecutor:[BFExecutor mainThreadExecutor]
withBlock:^id(BFTask *task) {
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];

@try {
if (self.exception) {
//TODO: (nlutsenko) Add more context, by passing a `_cmd` from the caller method
PFLogException(self.exception);
@throw self.exception;
}

if (!self.cancelled || executeIfCancelled) {
resultBlock(self.result, self.error);
}
} @finally {
tcs.result = nil;
}

return tcs.task;
}];
}
Expand Down Expand Up @@ -121,8 +113,6 @@ - (id)waitForResult:(NSError **)error withMainThreadWarning:(BOOL)warningEnabled
}
if (self.cancelled) {
return nil;
} else if (self.exception) {
@throw self.exception;
}
if (self.error && error) {
*error = self.error;
Expand Down
4 changes: 1 addition & 3 deletions Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl
[tcs cancel];
} else if (task.error != nil) {
[tcs setError:task.error];
} else if (task.exception != nil) {
[tcs setException:task.exception];
} else {
[tcs setResult:object];
}
Expand Down Expand Up @@ -431,7 +429,7 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl
user:user
pin:pin
isCount:YES] continueWithSuccessBlock:^id(BFTask *task) {
if (!task.cancelled && !task.error && !task.exception) {
if (!task.cancelled && !task.faulted) {
NSArray *result = task.result;
return @(result.count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ - (BFTask *)openDatabaseWithNameAsync:(NSString *)name {
NSError *error = task.error;
if (error) {
[taskCompletionSource trySetError:error];
} else {
[taskCompletionSource trySetException:task.exception];
}
} else if (task.cancelled) {
[taskCompletionSource trySetCancelled];
Expand Down
7 changes: 1 addition & 6 deletions Parse/Internal/PFAsyncTaskQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ - (BFTask *)enqueue:(BFContinuationBlock)block {
_tail = [_tail continueAsyncWithBlock:block];
[_tail continueAsyncWithBlock:^id(BFTask *task) {
if (task.faulted) {
NSError *error = task.error;
if (error) {
[source trySetError:error];
} else {
[source trySetException:task.exception];
}
[source trySetError:task.error];
} else if (task.cancelled) {
[source trySetCancelled];
} else {
Expand Down
8 changes: 2 additions & 6 deletions Parse/Internal/PFEventuallyQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ - (BFTask *)enqueueCommandInBackground:(id<PFNetworkCommand>)command withObject:
return [[[self _enqueueCommandInBackground:command
object:object
identifier:identifier] continueWithBlock:^id(BFTask *task) {
if (task.error || task.exception || task.cancelled) {
if (task.faulted || task.cancelled) {
[self.testHelper notify:PFEventuallyQueueEventCommandNotEnqueued];
if (task.error) {
taskCompletionSource.error = task.error;
} else if (task.exception) {
taskCompletionSource.exception = task.exception;
} else if (task.cancelled) {
[taskCompletionSource cancel];
}
Expand Down Expand Up @@ -305,8 +303,6 @@ - (void)_runCommandsWithRetriesCount:(NSUInteger)retriesCount {
// Notify anyone waiting that the operation is completed.
if (resultTask.error) {
taskCompletionSource.error = resultTask.error;
} else if (resultTask.exception) {
taskCompletionSource.exception = resultTask.exception;
} else if (resultTask.cancelled) {
[taskCompletionSource cancel];
} else {
Expand Down Expand Up @@ -340,7 +336,7 @@ - (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command
[_taskCompletionSources removeObjectForKey:identifier];
});

if (resultTask.exception || resultTask.error || resultTask.cancelled) {
if (resultTask.faulted || resultTask.cancelled) {
[self.testHelper notify:PFEventuallyQueueEventCommandFailed];
} else {
[self.testHelper notify:PFEventuallyQueueEventCommandSucceded];
Expand Down
2 changes: 1 addition & 1 deletion Parse/Internal/PFPinningEventuallyQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ - (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command
[_eventuallyPinUUIDQueue removeObject:identifier];
});

if (resultTask.cancelled || resultTask.exception || resultTask.error) {
if (resultTask.cancelled || resultTask.faulted) {
return resultTask;
}

Expand Down
21 changes: 13 additions & 8 deletions Parse/Internal/Query/Controller/PFCachedQueryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
} cancellationToken:cancellationToken];
}
break;
case kPFCachePolicyCacheOnly:
{
case kPFCachePolicyCacheOnly: {
return [self _runNetworkCommandAsyncFromCache:command
withCancellationToken:cancellationToken
forQueryState:queryState];
Expand All @@ -83,9 +82,9 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
@weakify(self);
return [networkTask continueWithBlock:^id(BFTask *task) {
@strongify(self);
if (task.cancelled || task.exception) {
if (task.cancelled) {
return task;
} else if (task.error) {
} else if (task.faulted) {
return [self _runNetworkCommandAsyncFromCache:command
withCancellationToken:cancellationToken
forQueryState:queryState];
Expand All @@ -111,11 +110,17 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
} cancellationToken:cancellationToken];
}
break;
case kPFCachePolicyCacheThenNetwork:
PFConsistencyAssertionFailure(@"kPFCachePolicyCacheThenNetwork is not implemented as a runner.");
case kPFCachePolicyCacheThenNetwork: {
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery
message:@"Cache then network is not supported directly in PFCachedQueryController."];
return [BFTask taskWithError:error];
}
break;
default:
PFConsistencyAssertionFailure(@"Unrecognized cache policy: %d", queryState.cachePolicy);
default: {
NSString *message = [NSString stringWithFormat:@"Unrecognized cache policy: %d", queryState.cachePolicy];
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery message:message];
return [BFTask taskWithError:error];
}
break;
}
return nil;
Expand Down
23 changes: 6 additions & 17 deletions Parse/PFObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
}];

return [[BFTask taskForCompletionOfAllTasks:handleSaveTasks] continueAsyncWithBlock:^id(BFTask *task) {
if (commandRunnerTask.error || commandRunnerTask.cancelled || commandRunnerTask.exception) {
if (commandRunnerTask.faulted || commandRunnerTask.cancelled) {
return commandRunnerTask;
}

// Reiterate saveAll tasks, return first error.
for (BFTask *handleSaveTask in handleSaveTasks) {
if (handleSaveTask.error || handleSaveTask.exception) {
if (handleSaveTask.faulted) {
return handleSaveTask;
}
}
Expand All @@ -525,20 +525,9 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
}

return [[BFTask taskForCompletionOfAllTasks:tasks] continueWithBlock:^id(BFTask *task) {
// Return the first exception, instead of the aggregated one
// for the sake of compatability with old versions

if ([task.exception.name isEqualToString:BFTaskMultipleExceptionsException]) {
NSException *firstException = [task.exception.userInfo[@"exceptions"] firstObject];
if (firstException) {
return [BFTask taskWithException:firstException];
}
}

if (task.error || task.cancelled || task.exception) {
if (task.cancelled || task.faulted) {
return task;
}

return @YES;
}];
}];
Expand Down Expand Up @@ -856,7 +845,7 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
BFTask *resultTask = [BFTask taskWithResult:object];

// Only delete if we successfully pin it so that it retries the migration next time.
if (!task.error && !task.exception && !task.cancelled) {
if (!task.faulted && !task.cancelled) {
NSString *path = [[Parse _currentManager].fileManager parseDataItemPathForPathComponent:fileName];
return [[PFFileManager removeItemAtPathAsync:path] continueWithBlock:^id(BFTask *task) {
// We don't care if it fails to delete the file, so return the
Expand Down Expand Up @@ -1098,7 +1087,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
}
saveTask = [saveTask continueWithBlock:^id(BFTask *task) {
@try {
if (!task.isCancelled && !task.exception && !task.error) {
if (!task.isCancelled && !task.faulted) {
PFCommandResult *result = task.result;
// PFPinningEventuallyQueue handle save result directly.
if (![Parse _currentManager].offlineStoreLoaded) {
Expand Down Expand Up @@ -1405,7 +1394,7 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
return [[Parse _currentManager].commandRunner runCommandAsync:command
withOptions:PFCommandRunningOptionRetryIfFailed];
}] continueAsyncWithBlock:^id(BFTask *task) {
if (task.isCancelled || task.exception || task.error) {
if (task.cancelled || task.faulted) {
// If there was an error, we want to roll forward the save changes before rethrowing.
BFTask *commandRunnerTask = task;
return [[self handleSaveResultAsync:nil] continueWithBlock:^id(BFTask *task) {
Expand Down
4 changes: 2 additions & 2 deletions Parse/PFUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ - (BFTask *)handleSignUpResultAsync:(BFTask *)task {
BFTask *signUpTask = task;

// Bail-out early, but still make sure that super class handled the result
if (task.error || task.cancelled || task.exception) {
if (task.faulted || task.cancelled) {
return [[super handleSaveResultAsync:nil] continueWithBlock:^id(BFTask *task) {
return signUpTask;
}];
Expand Down Expand Up @@ -520,7 +520,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
[currentUser rebuildEstimatedData];

return [[[[currentUser saveInBackground] continueWithBlock:^id(BFTask *task) {
if (task.error || task.cancelled || task.exception) {
if (task.faulted || task.cancelled) {
@synchronized ([currentUser lock]) {
if (oldUsername) {
currentUser.username = oldUsername;
Expand Down
20 changes: 19 additions & 1 deletion Tests/Unit/ConfigControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@
#import "PFConfig.h"
#import "PFConfigController.h"
#import "PFTestCase.h"
#import "PFPersistenceController.h"
#import "PFPersistenceGroup.h"

@protocol ConfigControllerDataSource <PFCommandRunnerProvider, PFPersistenceControllerProvider>

@end

@interface ConfigControllerTests : PFTestCase

@end

@implementation ConfigControllerTests

///--------------------------------------
#pragma mark - Helpers
///--------------------------------------

- (PFPersistenceController *)mockedPersistenceController {
id controller = PFStrictClassMock([PFPersistenceController class]);
id group = PFProtocolMock(@protocol(PFPersistenceGroup));
OCMStub([controller getPersistenceGroupAsync]).andReturn([BFTask taskWithResult:group]);
return controller;
}

///--------------------------------------
#pragma mark - Tests
///--------------------------------------
Expand All @@ -50,8 +67,9 @@ - (void)testFetch {
forCommandsPassingTest:^BOOL(id obj) {
return YES;
}];
id dataSource = PFStrictProtocolMock(@protocol(PFCommandRunnerProvider));
id dataSource = PFStrictProtocolMock(@protocol(ConfigControllerDataSource));
OCMStub([dataSource commandRunner]).andReturn(commandRunner);
OCMStub([dataSource persistenceController]).andReturn([self mockedPersistenceController]);

PFConfigController *configController = [[PFConfigController alloc] initWithDataSource:dataSource];

Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/QueryCachedControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ - (void)testFindObjectsCacheThenNetwork {
[[controller findObjectsAsyncForQueryState:state
withCancellationToken:nil
user:nil] continueWithBlock:^id(BFTask *task) {
XCTAssertNotNil(task.exception);
XCTAssertNotNil(task.error);
[expectation fulfill];
return nil;
}];
Expand All @@ -310,7 +310,7 @@ - (void)testFindObjectsUnknownPolicy {
[[controller findObjectsAsyncForQueryState:state
withCancellationToken:nil
user:nil] continueWithBlock:^id(BFTask *task) {
XCTAssertNotNil(task.exception);
XCTAssertNotNil(task.error);
[expectation fulfill];
return nil;
}];
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
ignore:
- Tests/.*
status:
project:
default:
target: 65
patch: false
changes: false
comment: false