Please, don’t crash again.. :(

code_crash

Code crashing, a common problem with normally very good reasons, and, sometimes, very poor ones.

Recently I had a problem where a crash occurred only when an application previously installed and used, would crash once a new update from the App Store would come. It was Google Analytics actually that gave me the bad news. It was something in this order:

NSInvalidArgumentException Trace: 0x0006d6bd MyApp 0x0006f2bd MyApp start_wqthread

What the hell is this, I wonder… In the meantime, someone was able to provide me his device’s crash logs. After trying to re-symbolicate them, nothing came out of them (well, at least the way I wanted…):

Last Exception Backtrace:
0 CoreFoundation 0x3241329e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3a13b97a objc_exception_throw + 26
2 CoreFoundation 0x3235d8d4 -[__NSArrayM insertObject:atIndex:] + 764
3 MyApp 0x0009985a 0x92000 + 30810
4 MyApp 0x0009b4f0 0x92000 + 38128
5 libdispatch.dylib 0x3a55311a _dispatch_call_block_and_release + 6
6 libdispatch.dylib 0x3a55795c _dispatch_root_queue_drain + 248
7 libdispatch.dylib 0x3a557abc _dispatch_worker_thread2 + 80
8 libsystem_c.dylib 0x3a587a0c _pthread_wqthread + 356
9 libsystem_c.dylib 0x3a5878a0 start_wqthread + 4

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x3a628eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3a629048 mach_msg + 36
2 CoreFoundation 0x323e8040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x323e6d5a __CFRunLoopRun + 810
4 CoreFoundation 0x32359eb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x32359d44 CFRunLoopRunInMode + 100
6 GraphicsServices 0x35f322e6 GSEventRunModal + 70
7 UIKit 0x3426f2fc UIApplicationMain + 1116
8 MyApp 0x000935fe 0x92000 + 5630
9 libdyld.dylib 0x3a572b1c start + 0

Ok, not too bad now. Still, I was not able to see exactly the issue… I now that the crash is here:

2 CoreFoundation 0x3235d8d4 -[__NSArrayM insertObject:atIndex:] + 764

But, where exactly?? In a code where you have more than 50 addObject: (addObject: is converted to a insertObject:atIndex: under the hood) it’s a bit difficult to actually know where the problem resides, and in what conditions it arises. After a loot of searching:

I gave up. I just wasn’t able to re-symbolicate the damn logs. I found out that the fact of having spaces and special characters on the App name, could produce strange conditions for re-symbolicating. With that knowledge and the hope that I could reproduce the same behavior by using TestFlight, I was able to track more or less the problem (with more than 20 builds, in which build I would comment and uncomment code) I found the issue!

So what it was??? Well, something like this:

NSMutableDictionary *cache = [NSKeyedUnarchiver unarchiveObjectWithFile:cachePath];

Somehow it seems that my local cache get’s corrupted after a legitime update from the AppStore (or other place). To fix this, I used a @try @catch. Again, the problem persisted, and by that time I realized that I had two bugs, because the app started crashing somewhere else… As you might imagine, I was really pissed by now, so I asked for the help of professionals and although they have one of the best costumer support I ever seen (replying to emails at 11pm in a Saturday…) I wasn’t completely able to find the issue. Sure I could track in more detail my fake crashes (that I was provoking on purposes to test the tool), but, unfortunately, not the real problem…

So what now?? I changed the name of my app to something simple (3 letters) uploaded to TestFlight and the goddamnit Xcode was able to symbolicate it. The issue? Don’t add a nil object to an array

Advertisements
Tagged , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: