Skip to content

Commit a192f4b

Browse files
committed
Remove all usages of BFTask.exception APIs.
1 parent 2f70f59 commit a192f4b

File tree

10 files changed

+27
-53
lines changed

10 files changed

+27
-53
lines changed

Parse/Internal/BFTask+Private.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,13 @@ - (BFTask *)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
6565
return [self continueWithExecutor:[BFExecutor mainThreadExecutor]
6666
withBlock:^id(BFTask *task) {
6767
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];
68-
6968
@try {
70-
if (self.exception) {
71-
//TODO: (nlutsenko) Add more context, by passing a `_cmd` from the caller method
72-
PFLogException(self.exception);
73-
@throw self.exception;
74-
}
75-
7669
if (!self.cancelled || executeIfCancelled) {
7770
resultBlock(self.result, self.error);
7871
}
7972
} @finally {
8073
tcs.result = nil;
8174
}
82-
8375
return tcs.task;
8476
}];
8577
}
@@ -121,8 +113,6 @@ - (id)waitForResult:(NSError **)error withMainThreadWarning:(BOOL)warningEnabled
121113
}
122114
if (self.cancelled) {
123115
return nil;
124-
} else if (self.exception) {
125-
@throw self.exception;
126116
}
127117
if (self.error && error) {
128118
*error = self.error;

Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl
272272
[tcs cancel];
273273
} else if (task.error != nil) {
274274
[tcs setError:task.error];
275-
} else if (task.exception != nil) {
276-
[tcs setException:task.exception];
277275
} else {
278276
[tcs setResult:object];
279277
}
@@ -431,7 +429,7 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl
431429
user:user
432430
pin:pin
433431
isCount:YES] continueWithSuccessBlock:^id(BFTask *task) {
434-
if (!task.cancelled && !task.error && !task.exception) {
432+
if (!task.cancelled && !task.faulted) {
435433
NSArray *result = task.result;
436434
return @(result.count);
437435
}

Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabaseController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ - (BFTask *)openDatabaseWithNameAsync:(NSString *)name {
5454
NSError *error = task.error;
5555
if (error) {
5656
[taskCompletionSource trySetError:error];
57-
} else {
58-
[taskCompletionSource trySetException:task.exception];
5957
}
6058
} else if (task.cancelled) {
6159
[taskCompletionSource trySetCancelled];

Parse/Internal/PFAsyncTaskQueue.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ - (BFTask *)enqueue:(BFContinuationBlock)block {
5353
NSError *error = task.error;
5454
if (error) {
5555
[source trySetError:error];
56-
} else {
57-
[source trySetException:task.exception];
5856
}
5957
} else if (task.cancelled) {
6058
[source trySetCancelled];

Parse/Internal/PFEventuallyQueue.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ - (BFTask *)enqueueCommandInBackground:(id<PFNetworkCommand>)command withObject:
106106
return [[[self _enqueueCommandInBackground:command
107107
object:object
108108
identifier:identifier] continueWithBlock:^id(BFTask *task) {
109-
if (task.error || task.exception || task.cancelled) {
109+
if (task.faulted || task.cancelled) {
110110
[self.testHelper notify:PFEventuallyQueueEventCommandNotEnqueued];
111111
if (task.error) {
112112
taskCompletionSource.error = task.error;
113-
} else if (task.exception) {
114-
taskCompletionSource.exception = task.exception;
115113
} else if (task.cancelled) {
116114
[taskCompletionSource cancel];
117115
}
@@ -305,8 +303,6 @@ - (void)_runCommandsWithRetriesCount:(NSUInteger)retriesCount {
305303
// Notify anyone waiting that the operation is completed.
306304
if (resultTask.error) {
307305
taskCompletionSource.error = resultTask.error;
308-
} else if (resultTask.exception) {
309-
taskCompletionSource.exception = resultTask.exception;
310306
} else if (resultTask.cancelled) {
311307
[taskCompletionSource cancel];
312308
} else {
@@ -340,7 +336,7 @@ - (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command
340336
[_taskCompletionSources removeObjectForKey:identifier];
341337
});
342338

343-
if (resultTask.exception || resultTask.error || resultTask.cancelled) {
339+
if (resultTask.faulted || resultTask.cancelled) {
344340
[self.testHelper notify:PFEventuallyQueueEventCommandFailed];
345341
} else {
346342
[self.testHelper notify:PFEventuallyQueueEventCommandSucceded];

Parse/Internal/PFPinningEventuallyQueue.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ - (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command
212212
[_eventuallyPinUUIDQueue removeObject:identifier];
213213
});
214214

215-
if (resultTask.cancelled || resultTask.exception || resultTask.error) {
215+
if (resultTask.cancelled || resultTask.faulted) {
216216
return resultTask;
217217
}
218218

Parse/Internal/Query/Controller/PFCachedQueryController.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
6868
} cancellationToken:cancellationToken];
6969
}
7070
break;
71-
case kPFCachePolicyCacheOnly:
72-
{
71+
case kPFCachePolicyCacheOnly: {
7372
return [self _runNetworkCommandAsyncFromCache:command
7473
withCancellationToken:cancellationToken
7574
forQueryState:queryState];
@@ -83,9 +82,9 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
8382
@weakify(self);
8483
return [networkTask continueWithBlock:^id(BFTask *task) {
8584
@strongify(self);
86-
if (task.cancelled || task.exception) {
85+
if (task.cancelled) {
8786
return task;
88-
} else if (task.error) {
87+
} else if (task.faulted) {
8988
return [self _runNetworkCommandAsyncFromCache:command
9089
withCancellationToken:cancellationToken
9190
forQueryState:queryState];
@@ -111,11 +110,17 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command
111110
} cancellationToken:cancellationToken];
112111
}
113112
break;
114-
case kPFCachePolicyCacheThenNetwork:
115-
PFConsistencyAssertionFailure(@"kPFCachePolicyCacheThenNetwork is not implemented as a runner.");
113+
case kPFCachePolicyCacheThenNetwork: {
114+
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery
115+
message:@"Cache then network is not supported directly in PFCachedQueryController."];
116+
return [BFTask taskWithError:error];
117+
}
116118
break;
117-
default:
118-
PFConsistencyAssertionFailure(@"Unrecognized cache policy: %d", queryState.cachePolicy);
119+
default: {
120+
NSString *message = [NSString stringWithFormat:@"Unrecognized cache policy: %d", queryState.cachePolicy];
121+
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery message:message];
122+
return [BFTask taskWithError:error];
123+
}
119124
break;
120125
}
121126
return nil;

Parse/PFObject.m

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,13 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
505505
}];
506506

507507
return [[BFTask taskForCompletionOfAllTasks:handleSaveTasks] continueAsyncWithBlock:^id(BFTask *task) {
508-
if (commandRunnerTask.error || commandRunnerTask.cancelled || commandRunnerTask.exception) {
508+
if (commandRunnerTask.faulted || commandRunnerTask.cancelled) {
509509
return commandRunnerTask;
510510
}
511511

512512
// Reiterate saveAll tasks, return first error.
513513
for (BFTask *handleSaveTask in handleSaveTasks) {
514-
if (handleSaveTask.error || handleSaveTask.exception) {
514+
if (handleSaveTask.faulted) {
515515
return handleSaveTask;
516516
}
517517
}
@@ -525,20 +525,9 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
525525
}
526526

527527
return [[BFTask taskForCompletionOfAllTasks:tasks] continueWithBlock:^id(BFTask *task) {
528-
// Return the first exception, instead of the aggregated one
529-
// for the sake of compatability with old versions
530-
531-
if ([task.exception.name isEqualToString:BFTaskMultipleExceptionsException]) {
532-
NSException *firstException = [task.exception.userInfo[@"exceptions"] firstObject];
533-
if (firstException) {
534-
return [BFTask taskWithException:firstException];
535-
}
536-
}
537-
538-
if (task.error || task.cancelled || task.exception) {
528+
if (task.cancelled || task.faulted) {
539529
return task;
540530
}
541-
542531
return @YES;
543532
}];
544533
}];
@@ -856,7 +845,7 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
856845
BFTask *resultTask = [BFTask taskWithResult:object];
857846

858847
// Only delete if we successfully pin it so that it retries the migration next time.
859-
if (!task.error && !task.exception && !task.cancelled) {
848+
if (!task.faulted && !task.cancelled) {
860849
NSString *path = [[Parse _currentManager].fileManager parseDataItemPathForPathComponent:fileName];
861850
return [[PFFileManager removeItemAtPathAsync:path] continueWithBlock:^id(BFTask *task) {
862851
// We don't care if it fails to delete the file, so return the
@@ -1098,7 +1087,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
10981087
}
10991088
saveTask = [saveTask continueWithBlock:^id(BFTask *task) {
11001089
@try {
1101-
if (!task.isCancelled && !task.exception && !task.error) {
1090+
if (!task.isCancelled && !task.faulted) {
11021091
PFCommandResult *result = task.result;
11031092
// PFPinningEventuallyQueue handle save result directly.
11041093
if (![Parse _currentManager].offlineStoreLoaded) {
@@ -1405,7 +1394,7 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
14051394
return [[Parse _currentManager].commandRunner runCommandAsync:command
14061395
withOptions:PFCommandRunningOptionRetryIfFailed];
14071396
}] continueAsyncWithBlock:^id(BFTask *task) {
1408-
if (task.isCancelled || task.exception || task.error) {
1397+
if (task.cancelled || task.faulted) {
14091398
// If there was an error, we want to roll forward the save changes before rethrowing.
14101399
BFTask *commandRunnerTask = task;
14111400
return [[self handleSaveResultAsync:nil] continueWithBlock:^id(BFTask *task) {

Parse/PFUser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ - (BFTask *)handleSignUpResultAsync:(BFTask *)task {
256256
BFTask *signUpTask = task;
257257

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

522522
return [[[[currentUser saveInBackground] continueWithBlock:^id(BFTask *task) {
523-
if (task.error || task.cancelled || task.exception) {
523+
if (task.faulted || task.cancelled) {
524524
@synchronized ([currentUser lock]) {
525525
if (oldUsername) {
526526
currentUser.username = oldUsername;

Tests/Unit/QueryCachedControllerTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ - (void)testFindObjectsCacheThenNetwork {
294294
[[controller findObjectsAsyncForQueryState:state
295295
withCancellationToken:nil
296296
user:nil] continueWithBlock:^id(BFTask *task) {
297-
XCTAssertNotNil(task.exception);
297+
XCTAssertNotNil(task.error);
298298
[expectation fulfill];
299299
return nil;
300300
}];
@@ -310,7 +310,7 @@ - (void)testFindObjectsUnknownPolicy {
310310
[[controller findObjectsAsyncForQueryState:state
311311
withCancellationToken:nil
312312
user:nil] continueWithBlock:^id(BFTask *task) {
313-
XCTAssertNotNil(task.exception);
313+
XCTAssertNotNil(task.error);
314314
[expectation fulfill];
315315
return nil;
316316
}];

0 commit comments

Comments
 (0)