Skip to content

Commit aa269ca

Browse files
committed
Adds PFPrecondition instead of Exception when saving cycles
1 parent 41f63b0 commit aa269ca

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Parse/Parse/Internal/PFAssert.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ if (!(condition)) { \
8282
return [PFErrorUtilities errorWithCode:-1 message:[NSString stringWithFormat:description, ##__VA_ARGS__]];\
8383
}
8484

85+
#define PFPreconditionWithTask(condition, description, ...) \
86+
if (!(condition)) { \
87+
return [BFTask taskWithError:[PFErrorUtilities errorWithCode:-1 message:[NSString stringWithFormat:description, ##__VA_ARGS__]]];\
88+
}
89+
8590
/**
8691
Raises an `NSInternalInconsistencyException`. Use `description` to supply the way to fix the exception.
8792
*/

Parse/Parse/PFObject.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,10 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
456456
}
457457
remaining = nextBatch;
458458

459-
if (current.count == 0) {
460-
// We do cycle-detection when building the list of objects passed to this
461-
// function, so this should never get called. But we should check for it
462-
// anyway, so that we get an exception instead of an infinite loop.
463-
PFConsistencyAssertionFailure(@"Unable to save a PFObject with a relation to a cycle.");
464-
}
459+
// We do cycle-detection when building the list of objects passed to this
460+
// function, so this should never get called. But we should check for it
461+
// anyway, so that we get an exception instead of an infinite loop.
462+
PFPreconditionWithTask(current.count != 0, @"Unable to save a PFObject with a relation to a cycle.");
465463

466464
// If a lazy user is one of the objects in the array, resolve its laziness now and
467465
// remove it from the list of things to save.
@@ -622,12 +620,10 @@ + (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object currentUse
622620
}
623621
remaining = nextBatch;
624622

625-
if (current.count == 0) {
626-
// We do cycle-detection when building the list of objects passed to this
627-
// function, so this should never get called. But we should check for it
628-
// anyway, so that we get an exception instead of an infinite loop.
629-
PFConsistencyAssertionFailure(@"Unable to save a PFObject with a relation to a cycle.");
630-
}
623+
// We do cycle-detection when building the list of objects passed to this
624+
// function, so this should never get called. But we should check for it
625+
// anyway, so that we get an exception instead of an infinite loop.
626+
PFPrecondition(current.count != 0, @"Unable to save a PFObject with a relation to a cycle.");
631627

632628
// If a lazy user is one of the objects in the array, resolve its laziness now and
633629
// remove it from the list of things to save.

0 commit comments

Comments
 (0)