Skip to content
Browse files

Add RKLog helper for displaying detailed key-value validation failure…

… information. closes #750
  • Loading branch information...
1 parent dcef1b1 commit 5cecb58c2387f70b55474043e95c2a95b253fbb5 @blakewatters blakewatters committed May 21, 2012
Showing with 40 additions and 1 deletion.
  1. +2 −1 Code/ObjectMapping/RKObjectMappingOperation.m
  2. +6 −0 Code/Support/RKLog.h
  3. +32 −0 Code/Support/RKLog.m
View
3 Code/ObjectMapping/RKObjectMappingOperation.m
@@ -252,7 +252,8 @@ - (BOOL)validateValue:(id *)value atKeyPath:(NSString*)keyPath {
success = [self.destinationObject validateValue:value forKeyPath:keyPath error:&_validationError];
if (!success) {
if (_validationError) {
- RKLogError(@"Validation failed while mapping attribute at key path %@ to value %@. Error: %@", keyPath, *value, [_validationError localizedDescription]);
+ RKLogError(@"Validation failed while mapping attribute at key path '%@' to value %@. Error: %@", keyPath, *value, [_validationError localizedDescription]);
+ RKLogValidationError(_validationError);
} else {
RKLogWarning(@"Destination object %@ rejected attribute value %@ for keyPath %@. Skipping...", self.destinationObject, *value, keyPath);
}
View
6 Code/Support/RKLog.h
@@ -199,3 +199,9 @@ void RKLogInitialize(void);
Trace or 6
*/
void RKLogConfigureFromEnvironment(void);
+
+/**
+ Logs extensive information about an NSError generated as the results
+ of a failed key-value validation error.
+ */
+void RKLogValidationError(NSError *);
View
32 Code/Support/RKLog.m
@@ -127,3 +127,35 @@ int RKLogLevelForString(NSString *logLevel, NSString *envVarName)
return -1;
}
}
+
+void RKLogValidationError(NSError *validationError) {
+ if ([[validationError domain] isEqualToString:@"NSCocoaErrorDomain"]) {
+ NSDictionary *userInfo = [validationError userInfo];
+ NSArray *errors = [userInfo valueForKey:@"NSDetailedErrors"];
+ if (errors) {
+ for (NSError *detailedError in errors) {
+ NSDictionary *subUserInfo = [detailedError userInfo];
+ RKLogError(@"Core Data Save Error\n \
+ NSLocalizedDescription:\t\t%@\n \
+ NSValidationErrorKey:\t\t\t%@\n \
+ NSValidationErrorPredicate:\t%@\n \
+ NSValidationErrorObject:\n%@\n",
+ [subUserInfo valueForKey:@"NSLocalizedDescription"],
+ [subUserInfo valueForKey:@"NSValidationErrorKey"],
+ [subUserInfo valueForKey:@"NSValidationErrorPredicate"],
+ [subUserInfo valueForKey:@"NSValidationErrorObject"]);
+ }
+ }
+ else {
+ RKLogError(@"Core Data Save Error\n \
+ NSLocalizedDescription:\t\t%@\n \
+ NSValidationErrorKey:\t\t\t%@\n \
+ NSValidationErrorPredicate:\t%@\n \
+ NSValidationErrorObject:\n%@\n",
+ [userInfo valueForKey:@"NSLocalizedDescription"],
+ [userInfo valueForKey:@"NSValidationErrorKey"],
+ [userInfo valueForKey:@"NSValidationErrorPredicate"],
+ [userInfo valueForKey:@"NSValidationErrorObject"]);
+ }
+ }
+}

0 comments on commit 5cecb58

Please sign in to comment.
Something went wrong with that request. Please try again.