Skip to content

Commit e10e8fa

Browse files
author
Blake Watters
committed
Check the value of error before assigning to conform to NSError coding conventions
1 parent 0b40b66 commit e10e8fa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Code/RKValueTransformers.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ + (instancetype)keyedArchivingValueTransformer
248248
}
249249
@catch (NSException *exception) {
250250
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"An `%@` exception was encountered while attempting to unarchive the given inputValue.", [exception name]], @"exception": exception };
251-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorTransformationFailed userInfo:userInfo];
251+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorTransformationFailed userInfo:userInfo];
252252
return NO;
253253
}
254254
if (! [unarchivedValue isKindOfClass:outputValueClass]) {
255255
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Expected an `outputValueClass` of type `%@`, but the unarchived object is a `%@`.", outputValueClass, [unarchivedValue class]] };
256-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorTransformationFailed userInfo:userInfo];
256+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorTransformationFailed userInfo:userInfo];
257257
return NO;
258258
}
259259
*outputValue = unarchivedValue;
@@ -262,7 +262,7 @@ + (instancetype)keyedArchivingValueTransformer
262262
*outputValue = [NSKeyedArchiver archivedDataWithRootObject:inputValue];
263263
} else {
264264
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Expected an `inputValue` of type `NSData` or conforming to `NSCoding`, but got a `%@` which does not satisfy these expectation.", [inputValue class]] };
265-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
265+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
266266
return NO;
267267
}
268268
return YES;
@@ -433,7 +433,7 @@ + (instancetype)stringValueTransformer
433433
} transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, Class outputValueClass, NSError *__autoreleasing *error) {
434434
if (! [inputValue respondsToSelector:@selector(stringValue)]) {
435435
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: @"Expected an `inputValue` that responds to `stringValue`, but it does not." };
436-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
436+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
437437
return NO;
438438
}
439439
RKValueTransformerTestOutputValueClassIsSubclassOfClass(outputValueClass, [NSString class], error);
@@ -451,7 +451,7 @@ + (instancetype)objectToCollectionValueTransformer
451451
} transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, Class outputValueClass, NSError *__autoreleasing *error) {
452452
if (RKVTClassIsCollection([inputValue class])) {
453453
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Expected an `inputValue` that is not a collection, but got a `%@`.", [inputValue class]] };
454-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
454+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
455455
return NO;
456456
}
457457
RKValueTransformerTestOutputValueClassIsSubclassOfClass(outputValueClass, (@[ [NSArray class], [NSSet class], [NSOrderedSet class]]), error);
@@ -479,7 +479,7 @@ + (instancetype)mutableValueTransformer
479479
} transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputValueClass, NSError *__autoreleasing *error) {
480480
if (! [inputValue conformsToProtocol:@protocol(NSMutableCopying)]) {
481481
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Expected an `inputValue` that conforms to `NSMutableCopying`, but `%@` objects do not.", [inputValue class]] };
482-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
482+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
483483
return NO;
484484
}
485485
RKValueTransformerTestOutputValueClassIsSubclassOfClass(outputValueClass, mutableClasses, error);
@@ -497,7 +497,7 @@ + (instancetype)keyOfDictionaryValueTransformer
497497
} transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, Class outputValueClass, NSError *__autoreleasing *error) {
498498
if (! [inputValue conformsToProtocol:@protocol(NSCopying)]) {
499499
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: @"Expected an `inputValue` that conforms to `NSCopying`, but it does not." };
500-
*error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
500+
if (error) *error = [NSError errorWithDomain:RKValueTransformersErrorDomain code:RKValueTransformationErrorUntransformableInputValue userInfo:userInfo];
501501
return NO;
502502
}
503503
RKValueTransformerTestOutputValueClassIsSubclassOfClass(outputValueClass, [NSDictionary class], error);

0 commit comments

Comments
 (0)