Skip to content

Consistency errors #1237

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 39 commits into from
Jan 30, 2018
Merged

Consistency errors #1237

merged 39 commits into from
Jan 30, 2018

Conversation

flovilmart
Copy link
Contributor

@flovilmart flovilmart commented Jan 19, 2018

This PR addresses those crashes that started happening since bumping to Bolts 1.9.0.

Starting Bolts 1.9.0, the NSExceptions are not caught by Bolts anymore, and need to be handled differently.

The best way to handle errors is to go the old style objective-c error pointer passing strategy.

This impact a large portion of the codebase as we need to forward errors from the coder / decoder.

On the public side, this should not change anything, as all failable calls will be caught by an errored BFTask.

@flovilmart flovilmart requested a review from montymxb January 20, 2018 00:52
@flovilmart flovilmart added type:bug Impaired feature or lacking behavior that is likely assumed unbreak now labels Jan 20, 2018
@flovilmart
Copy link
Contributor Author

@montymxb as of now, it looks like all the PFConsistencyAsset calls are 'safe' and reporting proper errors to the users when 'developing'.

Errors that would occur in flight (when wrapped into an async task have been replaced by error pointers).

@flovilmart
Copy link
Contributor Author

Additionally @marcgovi, could you have a quick look?

@flovilmart
Copy link
Contributor Author

@montymxb as it stands now, I made a pre release 1.17.0-alpha.1 in order to be able to test it out in the wild, I also updated liveQuery as this project relies on the decoders which have changed their interface in order to support encoding failures. I tested on a project and it all look great.

@flovilmart flovilmart added this to the 1.17.0 milestone Jan 21, 2018
@flovilmart flovilmart closed this Jan 24, 2018
@flovilmart flovilmart reopened this Jan 24, 2018
Copy link
Contributor

@mt81 mt81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits then LGTM

NSDictionary *encodedDimensions = [[PFNoObjectEncoder objectEncoder] encodeObject:dimensions];
NSError *error;
NSDictionary *encodedDimensions = [[PFNoObjectEncoder objectEncoder] encodeObject:dimensions error:&error];
if (encodedDimensions == nil && error != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in objective c we don't have to check for nill != nil, but maybe it is more elegant this way ...

@@ -105,12 +108,13 @@ + (instancetype)commandFromDictionaryRepresentation:(NSDictionary *)dictionary {
PFRESTCommand *command = [self commandWithHTTPPath:dictionary[PFRESTCommandHTTPPathEncodingKey]
httpMethod:dictionary[PFRESTCommandHTTPMethodEncodingKey]
parameters:dictionary[PFRESTCommandParametersEncodingKey]
sessionToken:dictionary[PFRESTCommandSessionTokenEncodingKey]];
sessionToken:dictionary[PFRESTCommandSessionTokenEncodingKey]
error:nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to add the error handling here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be good if I understand the codepaths correctly

self.parameters = [[PFPointerOrLocalIdObjectEncoder objectEncoder] encodeObject:data];
BOOL modified = NO;
BOOL success = [[self class] forEachLocalIdIn:data doBlock:block modified:&modified error:error];
if (!success) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of something like this ?

     if ([[self class] forEachLocalIdIn:data doBlock:block modified:&modified error:error]) {
         self.parameters = [[PFPointerOrLocalIdObjectEncoder objectEncoder] encodeObject:data error:error];
         if (self.parameters && !(error && *error)) {
            return YES;
        }
      }
      return NO;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense.

@@ -131,6 +143,8 @@ + (NSDictionary *)findCommandParametersWithOrder:(NSString *)order
parameters[key] = obj;
}];

__block BOOL encodingHasErrored = NO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use encodingHasErroror encodingFailed?

if (![object isKindOfClass:[NSDictionary class]]) {
return object;
}

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[object count]];
__block BOOL hadFailed = NO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use fasFailed or didFail? Up to you...

NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects];
- (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder error:(NSError **)error {
NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects error: error];
if (!encodedObjects && error && *error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we usePFPreconditionBailOnError ?

NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects];
- (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder error:(NSError **)error {
NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects error:error];
if (!encodedObjects && error && *error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we usePFPreconditionBailOnError ?

NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects];
- (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder error:(NSError **)error {
NSMutableArray *encodedObjects = [objectEncoder encodeObject:self.objects error:error];
if (!encodedObjects && error && *error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we usePFPreconditionBailOnError ?

@@ -66,6 +114,7 @@ do {\
format:description, ##__VA_ARGS__]; \
} while(0)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line added... should we remove it?

}
return newArray;

} else if ([object isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:[object count]];
__block BOOL hasErrored = NO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasErrors ?

@flovilmart
Copy link
Contributor Author

thanks @mt81 i'll update with the nits!

@flovilmart flovilmart force-pushed the consistency-errors branch 2 times, most recently from 6828a72 to 25a5338 Compare January 24, 2018 18:47
@flovilmart flovilmart closed this Jan 26, 2018
@flovilmart flovilmart reopened this Jan 26, 2018
@flovilmart flovilmart closed this Jan 29, 2018
@flovilmart flovilmart reopened this Jan 29, 2018
@flovilmart flovilmart merged commit 61f3320 into master Jan 30, 2018
@flovilmart flovilmart deleted the consistency-errors branch January 30, 2018 18:41
flovilmart pushed a commit that referenced this pull request Feb 6, 2018
* 1. Fix typo PFPreconditionFailOnError and PFPreconditionFailAndSetError. 2. If there is a new object in OfflineStore, should not send the exception when the saved object update its OfflineStore cache

* Change the condition about newly saved object

* fix typo

* Revert to PFPreconditionBailOnError and PFPreconditionBailAndSetError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants