-
Notifications
You must be signed in to change notification settings - Fork 17
CKQueryOperation not returning records reliably #15
Comments
When the number of record is too large something different happens which could be the reason. It can either fail that the request was too large or it allows it but needs to batch the records by returning a cursor which is to be used in additional query operations. It sounds like you didn't get any records at all so it's more likely a flat out failure than a bug in the handling of the cursor situation. Since the error object is empty, which means that even no error information was returned, you could examine the lower level http error status code in CKWebRequest line 108 and look it up in this table: |
Thanks @malhal , it seems as though the response is coming back ok (since the CloudKit logs show the responses coming in and the database providing data back) but I was able to uncover a couple of parsing Errors in CKQueryOperation file, performCKOperation(). The result from that is giving me two errors:
and
Looks like the JSON that comes back isn't in the right format? |
Turn on CloudKit.verbose which will output the JSON and put it in a text editor and go to position 35373 and see what it looks like. |
When I enable CloudKit.verbose it only prints the JSON response from CloudKit when it is successful. I was able to get one to go through successfully and that character (35406) everything looks alright (as it should since it parsed it ok). Any tip on getting the JSON printout in the event of an error? I'm wondering if the "JSON text did not start with array or object and option to allow fragments not set" is indicating that a cursor came back before the initial JSON array and the parser is not knowing how to handle it since the response did not start with array? |
Ah yeh sorry, at line 200 in CKURLRequest.swift try something like: let dataString = NSString(data: data, encoding: .utf8) |
hmm, tried this and it still won't print anything: let dataString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) |
Also tried changing the jsonObject at like 201 to: but still have an error on the results. Prints twice: |
Also tried this before Serialization: And got this in the console:
This was only for one request but gave two prints of data received, both in the wrong format. |
@malhal I think I got it. `func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
I'll keep testing this but it is finally working with every request. |
Very sad, didReceive data appending to a mutable receivedData and using it in the completion is an absolutely basic pattern. Well done spotting it but I guess you'll need to proceed with caution using this project. |
I believe this issue occurs as URL Session Data Task is limited to how much data can be downloaded. This is a bug and I believe implementing URL Session Download Task in its place will fix this issue. |
Data task is correct it just needs the append to mutable data as mentioned. Download task is for retrieving a static file, I.e. something that may need to be resumed, and on iPhone something that can be set to continue in the background. |
I have been able to successfully make multiple CKQueryOperations and CKQuery but have one that seems to not reliably return results but instead returns a CKErrorDomain Code = 0 error. Here is a test function I'm trying to execute:
`func test() {
let query = CKQuery(recordType: "WatchlistBeer", predicate: NSPredicate(value: true))
let operation = CKQueryOperation(query: query)
}`
About 1 in 6 or 7 tries returns results, the rest of the time I get an error with code "0", failureReason = nil, localizedRecoverySuggestion = nil and debug description = Error Domain=CKErrorDomain Code=0 "(null)"
When I look at the live log on CloudKit dashboard the requests are showing successful with a response size that matches the size of the records when I get them back. I'm not sure where this is breaking as it seems as though CloudKit is getting the responses correctly and returning data. The response isn't huge, about 52kb and the error come back appropriately when I input the wrong record type or predicate. Not sure what I'm missing.
The text was updated successfully, but these errors were encountered: