Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#238: Log errors on encoding/decoding with the key name.

  • Loading branch information...
commit 659fac6db74e15f70015517eb5a266aa22c1e081 1 parent eac31d8
@dblock dblock authored
Showing with 35 additions and 25 deletions.
  1. +35 −25 Mantle/MTLModel+NSCoding.m
View
60 Mantle/MTLModel+NSCoding.m
@@ -141,13 +141,18 @@ - (id)decodeValueForKey:(NSString *)key withCoder:(NSCoder *)coder modelVersion:
return result;
}
- if (coderRequiresSecureCoding(coder)) {
- NSArray *allowedClasses = self.class.allowedSecureCodingClassesByPropertyKey[key];
- NSAssert(allowedClasses != nil, @"No allowed classes specified for securely decoding key \"%@\" on %@", key, self.class);
-
- return [coder decodeObjectOfClasses:[NSSet setWithArray:allowedClasses] forKey:key];
- } else {
- return [coder decodeObjectForKey:key];
+ @try {
+ if (coderRequiresSecureCoding(coder)) {
+ NSArray *allowedClasses = self.class.allowedSecureCodingClassesByPropertyKey[key];
+ NSAssert(allowedClasses != nil, @"No allowed classes specified for securely decoding key \"%@\" on %@", key, self.class);
+
+ return [coder decodeObjectOfClasses:[NSSet setWithArray:allowedClasses] forKey:key];
+ } else {
+ return [coder decodeObjectForKey:key];
+ }
+ } @catch (NSException *ex) {
+ NSLog(@"*** Caught exception decoding value for key \"%@\" on class %@: %@", key, self.class, ex);
+ @throw ex;
}
}
@@ -212,24 +217,29 @@ - (void)encodeWithCoder:(NSCoder *)coder {
NSDictionary *encodingBehaviors = self.class.encodingBehaviorsByPropertyKey;
[self.dictionaryValue enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
- // Skip nil values.
- if ([value isEqual:NSNull.null]) return;
-
- switch ([encodingBehaviors[key] unsignedIntegerValue]) {
- // This will also match a nil behavior.
- case MTLModelEncodingBehaviorExcluded:
- break;
-
- case MTLModelEncodingBehaviorUnconditional:
- [coder encodeObject:value forKey:key];
- break;
-
- case MTLModelEncodingBehaviorConditional:
- [coder encodeConditionalObject:value forKey:key];
- break;
-
- default:
- NSAssert(NO, @"Unrecognized encoding behavior %@ for key \"%@\"", encodingBehaviors[key], key);
+ @try {
+ // Skip nil values.
+ if ([value isEqual:NSNull.null]) return;
+
+ switch ([encodingBehaviors[key] unsignedIntegerValue]) {
+ // This will also match a nil behavior.
+ case MTLModelEncodingBehaviorExcluded:
+ break;
+
+ case MTLModelEncodingBehaviorUnconditional:
+ [coder encodeObject:value forKey:key];
+ break;
+
+ case MTLModelEncodingBehaviorConditional:
+ [coder encodeConditionalObject:value forKey:key];
+ break;
+
+ default:
+ NSAssert(NO, @"Unrecognized encoding behavior %@ on class %@ for key \"%@\"", self.class, encodingBehaviors[key], key);
+ }
+ } @catch (NSException *ex) {
+ NSLog(@"*** Caught exception encoding value for key \"%@\" on class %@: %@", key, self.class, ex);
+ @throw ex;
}
}];
}
Please sign in to comment.
Something went wrong with that request. Please try again.