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

Listing Transformation Error When Searching for Subreddits #72

Open
insanj opened this issue Aug 14, 2015 · 1 comment
Open

Listing Transformation Error When Searching for Subreddits #72

insanj opened this issue Aug 14, 2015 · 1 comment

Comments

@insanj
Copy link

insanj commented Aug 14, 2015

EDIT: Originally I believed this issue crashed the app in production. I think, however, the crash was due to my device's build being built via Xcode's debugger, which meant it's DEBUG tag was, understandably, YES, although I would have no way to inspect the @throw. So, although I still feel like this is an issue, it's unlikely it would be fatal for RedditKit clients. My bad!


Heya! Great work overall on this project, it's been a pleasure working with it. Unfortunately, I've stumbled upon a crash which I can't find a reasonable approach to get around.

I'm currently working on a search area for subreddits. Naturally, I employed the searchForSubredditsByName method in my search bar delegate's searchBarSearchButtonClicked, passing the search bar text if it passes a nil / empty string check. This works very well for most strings, however, I've found several one-word queries that will fail immediately. To test this, try typing in a great deal of 5-letter words (or fewer), such as Funny, Aww, Hello.

All of these crash for me, tracing up to Mantle's MTLModel. At this point the exception is @thrown in DEBUG, or just crashes in production. The exception reads:

NSException *   name:@"NSInvalidArgumentException" reason:@"[<RKSubreddit 0x1703b2b40> setNilValueForKey]: could not set nil as the value for the key totalSubscribers."    0x0000000170051cd0

Which led me to believe that the subreddit listing or initial subreddit object being provided by the request was mostly nil, rather than containing the expected wealth of information. After introspecting the construction of RKSubreddit objects by Mantle, it appears that every subreddit object begins with nil fields, making this situation difficult to differentiate. However, the listing objects normally provide at least a 0 for primitive values, rather than nil, as occurs during this crash:

<RKSubreddit: 0x7860c320, full name: (null)_(null), name: (null)> key: trafficPagePubliclyAccessible, value: (null)

At first I tried to swizzle or directly modify the properties or setNilValueForKey:, but neither were sustainable, considering every primitive value (including enums, of course) would have to be wrapped (and that doesn't quite solve the problem at the source), whereas the ideal solution would just throw out nil/invalid listing responses.

After setting up breakpoints and introspecting the object transformation process in MTLValidateAndSetValue (where the @throw is) I felt kind of stuck, and decided to send over my stack trance:

2015-08-14 10:51:39.021 Submarine[86396:15471818] *** Caught exception setting key "trafficPagePubliclyAccessible" : [<RKSubreddit 0x7bf2e180> setNilValueForKey]: could not set nil as the value for the key trafficPagePubliclyAccessible.
2015-08-14 10:51:39.024 Submarine[86396:15471818] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '[<RKSubreddit 0x7bf2e180> setNilValueForKey]: could not set nil as the value for the key trafficPagePubliclyAccessible.'
*** First throw call stack:
(
0   CoreFoundation                      0x0399d746 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x03624a97 objc_exception_throw + 44
2   CoreFoundation                      0x0399d66d +[NSException raise:format:] + 141
3   Foundation                          0x00c51255 -[NSObject(NSKeyValueCoding) setNilValueForKey:] + 95
4   Foundation                          0x00c4fc03 _NSSetCharValueForKeyInIvar + 86
5   Foundation                          0x00bae696 _NSSetUsingKeyValueSetter + 257
6   Foundation                          0x00bae58d -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
7   Submarine                           0x0023969e MTLValidateAndSetValue + 526
8   Submarine                           0x00239339 -[MTLModel initWithDictionary:error:] + 697
9   Submarine                           0x00238fbe +[MTLModel modelWithDictionary:error:] + 126
10  Submarine                           0x0022ad44 -[MTLJSONAdapter initWithJSONDictionary:modelClass:error:] + 7652
11  Submarine                           0x00227feb +[MTLJSONAdapter modelOfClass:fromJSONDictionary:error:] + 139
12  Submarine                           0x002736e5 +[RKObjectBuilder objectFromJSON:] + 421
13  Submarine                           0x002600b6 -[RKClient(Requests) objectsFromListingResponse:] + 966
14  Submarine                           0x0025e51e __75-[RKClient(Requests) listingTaskWithPath:parameters:pagination:completion:]_block_invoke_2 + 206
15  libdispatch.dylib                   0x040a85ea _dispatch_call_block_and_release + 15
16  libdispatch.dylib                   0x040cabef _dispatch_client_callout + 14
17  libdispatch.dylib                   0x040b21ef _dispatch_root_queue_drain + 1092
18  libdispatch.dylib                   0x040b3b70 _dispatch_worker_thread3 + 115
19  libsystem_pthread.dylib             0x0445d49e _pthread_wqthread + 1050
20  libsystem_pthread.dylib             0x0445afde start_wqthread + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException

...and open this issue to see what you thought, and what should be done to prevent crashes like this using a simple RedditKit function. Is this purely a Mantle issue? Any thoughts?

@insanj insanj changed the title Listing Transformation Crash When Searching for Subreddits Listing Transformation Error When Searching for Subreddits Aug 14, 2015
@UpasnaGandhi
Copy link

Hey ,

I am getting the same error while searching sub reddits by name even subscribing sub reddits by name. Are you able to find the solution for your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants