It was crashing when trying to build a callback argument NSArray with a nil object. NSError's are not guaranteed to have a NSLocalizedFailureReason, so this case should be handled.
This commit is contained in:
Andy Prock 2015-12-30 22:51:26 -08:00
parent 05b206deca
commit 41fc91c5cc
2 changed files with 6 additions and 6 deletions

View File

@ -126,8 +126,8 @@ NSString *const RCTUDPErrorDomain = @"RCTUDPErrorDomain";
NSNumber* tagNum = [NSNumber numberWithLong:msgTag]; NSNumber* tagNum = [NSNumber numberWithLong:msgTag];
RCTResponseSenderBlock callback = [self getPendingSend:tagNum]; RCTResponseSenderBlock callback = [self getPendingSend:tagNum];
if (callback) { if (callback) {
NSString* msg = [[error userInfo] valueForKey:@"NSLocalizedFailureReason"]; NSString *msg = error.localizedFailureReason ?: error.localizedDescription;
callback(@[msg]); callback(@[msg ?: @"unkown error"]);
[self dropPendingSend:tagNum]; [self dropPendingSend:tagNum];
} }
} }

View File

@ -61,8 +61,8 @@ RCT_EXPORT_METHOD(bind:(nonnull NSNumber*)cId
NSError *error = nil; NSError *error = nil;
if (![client bind:port address:address error:&error]) if (![client bind:port address:address error:&error])
{ {
NSString* msg = [[error userInfo] valueForKey:@"NSLocalizedFailureReason"]; NSString *msg = error.localizedFailureReason ?: error.localizedDescription;
callback(@[msg]); callback(@[msg ?: @"unkown error when binding"]);
return; return;
} }
@ -97,8 +97,8 @@ RCT_EXPORT_METHOD(setBroadcast:(nonnull NSNumber*)cId
NSError *error = nil; NSError *error = nil;
if (![client setBroadcast:flag error:&error]) if (![client setBroadcast:flag error:&error])
{ {
NSString* msg = [[error userInfo] valueForKey:@"NSLocalizedFailureReason"]; NSString *msg = error.localizedFailureReason ?: error.localizedDescription;
callback(@[msg]); callback(@[msg ?: @"unkown error when setBroadcast"]);
return; return;
} }
callback(@[[NSNull null]]); callback(@[[NSNull null]]);