1

Overview

  • When I use NSPersistentCloudKitContainer I get the following error / debug messages printed on the Xcode Debug Area.
  • I have logged into iCloud and I am testing on device
  • Syncing seems to happen fine
  • I am still using Development (not deployed to Production yet)
  • I tried with a new project by using the default code generated for by enabling CloudKit coredata sync and I still get the same messages.

Error / debug message printed on Xcode debug area

CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](36): Validating options: <NSCloudKitMirroringDelegateOptions: 0x600000760510> containerIdentifier:<MyContainerID> databaseScope:Private ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO useDeviceToDeviceEncryption:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x600003764210> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600003764220> metricsClient:<PFCloudKitMetricsClient: 0x600003764230> metadataPurger:<PFCloudKitMetadataPurger: 0x600003764240> scheduler:<null> notificationListener:<null> containerOptions:<null> defaultOperationConfiguration:<null> progressProvider:<NSPersistentCloudKitContainer: 0x60000205d200> test_useLegacySavePolicy:YES archivingUtilities:<PFCloudKitArchivingUtilities: 0x600003764250> bypassSchedulerActivityForInitialImport:NO
storeOptions: {
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600003b3a190>";
    NSPersistentHistoryTrackingKey = 1;
    NSPersistentStoreMirroringOptionsKey =     {
        NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600000c642a0>";
    };
    NSPersistentStoreRemoteChangeNotificationOptionKey = 1;
}
CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate observeChangesForStore:inPersistentStoreCoordinator:](416): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Observing store: <NSSQLCore: 0x14080aec0> (URL: file:///Users/<my home folder>/Library/Group%20Containers/group.<app name>/<filename>.sqlite)
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _setUpCloudKitIntegration](562): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Successfully enqueued setup request.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](3209): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Checking for pending requests.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(3222): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Executing: <NSCloudKitMirroringDelegateSetupRequest: 0x600001643f20> D3975DD0-1198-40F2-9D6A-B9994B9710B6
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](446): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE'

Questions:

  1. Are these errors on my part? Have I missed something?
  2. Or can these be ignored?
  3. Should I be filing a feedback / bug with Apple?
user1046037
  • 16,755
  • 12
  • 92
  • 138

1 Answers1

3

My app uses CoreData & CloudKit for some time. Initially, I was also worried by all the debugger logs, but by now I am ignoring most of them. This is done as follows:
In scheme/Run/Arguments/Arguments Passed On Launch add and check

-com.apple.CoreData.CloudKitDebug 0  
-com.apple.CoreData.Logging.stderr 0  

Some comments to you specific logs:
CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions: Apparently only info about the sync setup.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _setUpCloudKitIntegration]: As reported, the sync setup has been successfully enqueued and will be processed later
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]: Just an info about the activity of the sync process
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection: Seems to be an info that CoreDate & CloudKit integration has been done before and that a specific setup for a certain column is not needed.

Since a long time I am ignoring all these logs, and my CoreData & CloudKit works most time without any reported errors.

EDIT:

One can check if there are "real" sync errors: I register for NSPersistentCloudKitContainer.Event notifications (see the docs) and I am logging sync events with

    var currentPersistentCloudKitContainerEvents: [NSPersistentCloudKitContainer.Event] = []
//…
        NotificationCenter.default.addObserver(forName: NSPersistentCloudKitContainer.eventChangedNotification, object: nil, queue: .main) { notification in
            guard let event = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event else { return }
            let eventID = event.identifier
            let eventType = event.type
            var eventTypeString: String
            switch eventType {
                case .setup:  eventTypeString = "setup "
                case .import: eventTypeString = "import"
                case .export: eventTypeString = "export"
                @unknown default: eventTypeString = "unknown"
            }

            // Check if the event has already been recorded
            let alreadyRecordedEvent = self.currentPersistentCloudKitContainerEvents.first(where: { $0.identifier == eventID} )
            var index: Int
            if let recordedEvent = alreadyRecordedEvent {
                index = self.currentPersistentCloudKitContainerEvents.firstIndex(of: recordedEvent)!
                self.currentPersistentCloudKitContainerEvents[index] = event
            } else {
                index = self.currentPersistentCloudKitContainerEvents.count
                self.currentPersistentCloudKitContainerEvents.append(event)
                syncLog.log("Started:   \(eventTypeString, privacy: .public), ID: \(eventID, privacy: .public), now in progress: \(self.currentPersistentCloudKitContainerEvents.count, privacy: .public)")
            }
            let recordedEvent = self.currentPersistentCloudKitContainerEvents[index]
            
            if event.endDate != nil {
                // The event finished successfully or with error
                if recordedEvent.succeeded {
                    syncLog.log("Succeeded: \(eventTypeString, privacy: .public), ID: \(eventID, privacy: .public), now in progress: \(self.currentPersistentCloudKitContainerEvents.count - 1, privacy: .public)")
                } else {
                    syncLog.error("Did not succeed: \(eventTypeString, privacy: .public), ID: \(eventID, privacy: .public), now in progress: \(self.currentPersistentCloudKitContainerEvents.count - 1, privacy: .public)")
                    if let error = event.error {
                        self.handleError(error)
                    }
                }
                // Delete the terminated event
                self.currentPersistentCloudKitContainerEvents.remove(at: index)
                return
            }
            
        }  

Sync errors are those events that did not succeed. But such event can of course be retried.

A "real" error that I encounter now and then is e.g.

2022-11-21 08:01:51.456355+0100 ShopEasy![61491:2995577] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate resetAfterError:andKeepContainer:]  

but CoreData & CloudKit seems to recover.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
  • Thanks for answering, Just a few doubts: You are spot on with the launch arguments, I was using `-com.apple.CoreData.Logging.stderr 0` as well which does the trick. The launch argument contains `stderr` which is a bit worrying. I hope the hard errors still get displayed even when `-com.apple.CoreData.Logging.stderr 0`. Have you checked if any hard errors do get displayed in spite of setting those mention launch arguments? – user1046037 Nov 20 '22 at 17:01
  • 1
    Please see me edit above. – Reinhard Männer Nov 21 '22 at 07:04