MTLModel+NSCoding::decodeValueForKey does not provide enough information to debug exceptions #238

dblock opened this Issue Feb 12, 2014 · 3 comments


None yet

3 participants

dblock commented Feb 12, 2014

The method calls one of decodeObjectOfClasses or decodeObjectForKey:

- (id)decodeValueForKey:(NSString *)key withCoder:(NSCoder *)coder modelVersion:

        return [coder decodeObjectOfClasses:[NSSet setWithArray:allowedClasses] forKey:key];
    } else {
        return [coder decodeObjectForKey:key];

You can get an exception from this that looks like this:

-[NSKeyedUnarchiver decodeObjectForKey:]: missing class information for object
    0   CoreFoundation                      0x038a15e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x036248b6 objc_exception_throw + 44
    2   CoreFoundation                      0x038a13bb +[NSException raise:format:] + 139
    3   Foundation                          0x00fe404f _decodeObjectBinary + 719
    4   Foundation                          0x00fe3c15 _decodeObject + 340
    5   Foundation                          0x00fe3ab9 -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    6   Artsy                               0x00341da3 -[MTLModel(NSCoding) decodeValueForKey:withCoder:modelVersion:] + 1667
    7   Artsy                               0x003426f4 -[MTLModel(NSCoding) initWithCoder:] + 2036
    8   Foundation                          0x00fe4b2a _decodeObjectBinary + 3498
    9   Foundation                          0x00fe3c15 _decodeObject + 340
    10  Foundation                          0x00fe3ab9 -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    11  Foundation                          0x0105568d +[NSKeyedUnarchiver unarchiveObjectWithData:] + 106

Unfortunately this says nothing about the key being decoded, so you're left to setting breakpoints inside the implementation and looking for the last key being decoded to find out which one is the culprit.

A simple fix could be to try/catch and re-raise a more specific Mantle exception. LMK if you think that would be good enough and I'll code it up.

robb commented Feb 12, 2014

I think this could help tracking down things in the wild, but catching the exception and bubbling it up as an error may be preferrable?


When does this exception occur? I've never actually seen it myself.

@dblock dblock added a commit to dblock/Mantle that referenced this issue Feb 13, 2014
@dblock dblock #238: Log errors on encoding/decoding with the key name. 659fac6
@dblock dblock added a commit to dblock/Mantle that referenced this issue Feb 13, 2014
@dblock dblock Partial tests for #238. b5c4d7b
dblock commented Feb 13, 2014

Looks like some code has changed in Mantle that makes decoding work with my repro case. However, I was able to reproduce this in a test for encoding:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment