Recently, after Parse SDK update, I start getting the following exception when loading files on startup:
2015-11-08 13:23:15.088 MyApp[7219:471946] [Error]: Caught "NSInvalidArgumentException" with reason "*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument":
(
0 CoreFoundation 0x0000000110a07f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000011047edeb objc_exception_throw + 48
2 CoreFoundation 0x0000000110a07e7d +[NSException raise:format:] + 205
3 Foundation 0x000000011002cd48 -[NSData(NSData) initWithContentsOfFile:options:error:] + 95
4 Foundation 0x00000001100c5fcc +[NSData(NSData) dataWithContentsOfFile:options:error:] + 61
5 MyApp 0x000000010e828426 -[PFFile _cachedData] + 94
6 MyApp 0x000000010e886cac __62-[BFTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke + 83
7 MyApp 0x000000010e88658c __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 + 82
8 MyApp 0x000000010e8874ab __29+[BFExecutor defaultExecutor]_block_invoke_2 + 358
9 MyApp 0x000000010e887a15 -[BFExecutor execute:] + 65
10 MyApp 0x000000010e886510 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 138
11 MyApp 0x000000010e886110 -[BFTask runContinuations] + 396
12 MyApp 0x000000010e8859c6 -[BFTask trySetResult:] + 151
13 MyApp 0x000000010e883c4c -[BFTaskCompletionSource trySetResult:] + 79
14 MyApp 0x000000010e7e48b3 __28-[PFAsyncTaskQueue enqueue:]_block_invoke_2 + 198
15 MyApp 0x000000010e88658c __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 + 82
16 libdispatch.dylib 0x00000001145fce5d _dispatch_call_block_and_release + 12
17 libdispatch.dylib 0x000000011461d49b _dispatch_client_callout + 8
18 libdispatch.dylib 0x0000000114605bef _dispatch_root_queue_drain + 1829
19 libdispatch.dylib 0x00000001146054c5 _dispatch_worker_thread3 + 111
20 libsystem_pthread.dylib 0x000000011494ea9d _pthread_wqthread + 729
21 libsystem_pthread.dylib 0x000000011494c3dd start_wqthread + 13
).
Any ideas why PFFile is crashing? Does this mean that the local cache is not compatible with previous version and that I will have a huge problems when users update the app?
The problem was that I was creating a new PFFile
, assigning it so some object's column locally and not saving it back to Parse. When a new file was created it's url
property is nil
, which should be fine, since it's not yet online. After that I was fetching the parent object whos child was that file - this was eventually messing things up because then I close the app and next time opening I was trying to fetch the data of that PFFile
with url
property equal to nil
. That results in this exception above. A workaround suggested by a guy from Parse:
PFFile *file = object[fileKey];
if ((file != nil) && [file isKindOfClass:[PFFile class]] && (file.url == nil)) {
[object revertObjectForKey:fileKey];
}
After that fetching the object will bring the correct data from Parse servers.