SkygearIO / skygear-SDK-iOS

Skygear SDK for iOS
https://skygear.io
Other
10 stars 28 forks source link

`performCachedQuery` throws NSInvalidArgumentException #64

Closed david90 closed 7 years ago

david90 commented 7 years ago

Version: v0.19.0

Exception: 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: asset)' screen shot 2016-11-24 at 1 47 31 pm

Note:

cheungpat commented 7 years ago

@david90 need stack trace

david90 commented 7 years ago
2016-11-24 14:08:43.107 seanphotofeed[33014:1542804] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: asset)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010974234b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010689121e objc_exception_throw + 48
    2   CoreFoundation                      0x00000001096589b7 -[__NSDictionaryM setObject:forKey:] + 1047
    3   SKYKit                              0x000000010627349d __46-[SKYRecordDeserializer recordWithDictionary:]_block_invoke + 221
    4   CoreFoundation                      0x00000001096c99d6 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
    5   CoreFoundation                      0x00000001096c98da -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 202
    6   SKYKit                              0x0000000106272c32 -[SKYRecordDeserializer recordWithDictionary:] + 194
    7   SKYKit                              0x00000001062699c1 __40-[SKYQueryCache cachedResultsWithQuery:]_block_invoke + 113
    8   CoreFoundation                      0x00000001096d1c62 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
    9   CoreFoundation                      0x00000001096d1af2 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 194
    10  SKYKit                              0x0000000106269894 -[SKYQueryCache cachedResultsWithQuery:] + 452
    11  SKYKit                              0x000000010624a13e -[SKYDatabase performCachedQuery:completionHandler:] + 142
    12  seanphotofeed                       0x000000010613a1b1 _TZFC13seanphotofeed11PhotoHelper11retrieveAllfT12onCompletionFGSaCS_5Photo_T__T_ + 1505
    13  seanphotofeed                       0x00000001061401f2 _TFC13seanphotofeed14HomeController12reloadPhotosfT_T_ + 98
    14  seanphotofeed                       0x0000000106140102 _TFC13seanphotofeed14HomeController11viewDidLoadfT_T_ + 98
    15  seanphotofeed                       0x0000000106140172 _TToFC13seanphotofeed14HomeController11viewDidLoadfT_T_ + 34
    16  UIKit                               0x000000010761206d -[UIViewController loadViewIfRequired] + 1258
    17  UIKit                               0x00000001076184d6 -[UIViewController __viewWillAppear:] + 118
    18  UIKit                               0x0000000107643393 -[UINavigationController _startCustomTransition:] + 1290
    19  UIKit                               0x0000000107654008 -[UINavigationController _startDeferredTransitionIfNeeded:] + 697
    20  UIKit                               0x000000010765519b -[UINavigationController __viewWillLayoutSubviews] + 58
    21  UIKit                               0x000000010784c1b7 -[UILayoutContainerView layoutSubviews] + 223
    22  UIKit                               0x0000000107535344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
    23  QuartzCore                          0x000000010e9b7cdc -[CALayer layoutSublayers] + 146
    24  QuartzCore                          0x000000010e9ab7a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    25  QuartzCore                          0x000000010e9ab61e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    26  QuartzCore                          0x000000010e93962c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
    27  QuartzCore                          0x000000010e966713 _ZN2CA11Transaction6commitEv + 475
    28  UIKit                               0x000000010746a067 _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
    29  UIKit                               0x0000000107c79b30 __handleEventQueue + 5672
    30  CoreFoundation                      0x00000001096e7311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    31  CoreFoundation                      0x00000001096cc59c __CFRunLoopDoSources0 + 556
    32  CoreFoundation                      0x00000001096cba86 __CFRunLoopRun + 918
    33  CoreFoundation                      0x00000001096cb494 CFRunLoopRunSpecific + 420
    34  GraphicsServices                    0x000000010bcc1a6f GSEventRunModal + 161
    35  UIKit                               0x0000000107470f34 UIApplicationMain + 159
    36  seanphotofeed                       0x0000000106136c5f main + 111
    37  libdyld.dylib                       0x0000000109c9268d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
cheungpat commented 7 years ago

In addition to #69, I would suggest @ben181231 make a more fundamental fix to the problem:

The iOS SDK expects the server to send valid response. In case the server sends a response that the iOS SDK does not expect, SKYDataSerialization returns nil (which IMHO is the expected behavior). This caused nil being added to NSDictionary, which is illegal.

The SKYRecordDeserializer should, on encountering a nil value, do one of the following (your pick):

and also emits a log stating that the value of the key failed to deserialize.