Skip to content
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

CloudKitOperation: Error Handling #167

Merged

Conversation

danthorpe
Copy link
Member

The 4th phase of CloudKitOperation refactoring.

  • CloudKitOperation now subclasses RetryOperation.
  • Configuration still works. - possibly copy addConfigurationBlock concepts from BatchedCloudKitOperation.
  • BatchedCloudKitOperation should subclass RepeatedOperation?

Default Error Recovery

I think it would be great if the framework provided some convenient error handling for some of the more recoverable errors. Things like, not logged into iCloud for example. My thinking is a type CloudKitErrorHandler say, which can be used in conjunction with RetryOperation as the "error recovery block".

  • Cloud Kit Error Handling

There are going to be some pretty standard error responses.

  1. Fatal Log the error, and return .None (i.e. do not attempt to retry).
    • InternalError
    • MissingEntitlement
    • InvalidArguments
    • ServerRejectedRequest
    • AssetFileNotFound
    • IncompatibleVersion
    • ConstraintViolation
    • BadDatabase
    • QuotaExceeded
    • OperationCancelled
  2. Re-request after a delay.
    • NetworkUnavailable
    • NetworkFailure
    • ServiceUnavailable
    • RequestRateLimited
    • AssetFileModified
    • BatchRequestFailed
    • ZoneBusy

These will require a bit more thought:

  • PartialFailure
    Some items failed, but the operation succeeded overall
    Do not handle in anyway - should be handled by the framework consumer.
  • BadContainer
    Un-provisioned or unauthorized container. Try provisioning the container before retrying the operation.
    TODO: Look into what provisioning the container means.
    Exit immediately - with fatal error logs, this is a compile time issue.
  • NotAuthenticated
    Not authenticated (writing without being logged in, no user record)
  • PermissionFailure
    Access failure (save or fetch)
    This sounds like we could handle it automatically, with an Operation/Block which is an alert telling the user to log into iCloud. So, we don't retry, but we do add an AlertPresentation operation.
  • UnknownItem
    Record does not exist
  • ResultsTruncated
    Query results were truncated by the server
    Automatically adjust the parameters to fetch the next set of results?
  • ServerRecordChanged
    The record was rejected because the version on the server was different
    Automatically adjust the parameters and re-request?
  • ChangeTokenExpired
    The previousServerChangeToken value is too old and the client must re-sync from scratch
    Trigger a re-sync operation?
  • ZoneNotFound
    The specified zone does not exist on the server
    Add a new operation to create the Zone first, with dependencies setup.
  • LimitExceeded
    The request to the server was too large. Retry this request as a smaller batch.
    Automatically re-request as multiple batches?
  • UserDeletedZone
    The user deleted this zone through the settings UI. Your client should either remove its local data or prompt the user before attempting to re-upload any data to this zone.
    Retry with a UserConfirmationOperation?

@danthorpe danthorpe self-assigned this Jan 13, 2016
@danthorpe danthorpe added this to the 2.6 milestone Jan 13, 2016
@danthorpe danthorpe changed the title CloudKitOperation, phase 4: Error Handling CloudKitOperation: Error Handling Jan 13, 2016
@danthorpe
Copy link
Member Author

So, the way the error handling will work is something like this, (or will be)

// Fetch (all) Record Zones CloudKit Operation
let operation = CloudKitOperation { CKFetchRecordZonesOperation.fetchAllRecordZonesOperation() }

// Add custom error handlers
operation.setErrorHandlerForCode(.ConstraintViolation) { error, recommended in
    // Inspect the error
    // The recommended tuple is the "recommended" response. It might be .None.
    // This is the result of the default error handlers being applied to the "next"
    // delay & operation (using the generator provided at initialism).

    // For errors such as this (a constraint violation) you'll typically want to log the
    // info, and return .None (which is actually what the default error handler would do). 
}

// Add error handlers for any CKErrorCode 
operation.setErrorHandlerForCode(.PartialFailure) { error, recommended in
    // etc
}

Something weird is going on with the CloudKitOperation tests for sure.
@codecov-io
Copy link

Current coverage is 73.94%

Merging #167 into development will increase coverage by +1.95% as of 47f8d21

@@            development    #167   diff @@
===========================================
  Files                51      51       
  Stmts              3007    3278   +271
  Branches              0       0       
  Methods                               
===========================================
+ Hit                2165    2424   +259
  Partial               0       0       
- Missed              842     854    +12

Review entire Coverage Diff as of 47f8d21

Powered by Codecov. Updated on successful CI builds.

@danthorpe
Copy link
Member Author

Okay, going to merge this now, and work on a CloudKit example in another branch.

danthorpe added a commit that referenced this pull request Jan 15, 2016
…e_4_error_handling

CloudKitOperation: Error Handling
@danthorpe danthorpe merged commit 836395a into development Jan 15, 2016
@danthorpe danthorpe deleted the feature/OPR-167_cloud_kit_phase_4_error_handling branch January 16, 2016 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants