Apply OWSFail() in more places.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent c21a7673c8
commit 9dfebb2d4b

@ -366,7 +366,18 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
} }
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:url]; id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:url];
if (!dataSource) {
DDLogError(@"Application opened with URL with unloadable content: %@", url);
[OWSAlerts showAlertWithTitle:
NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE",
@"Title for the alert indicating the 'export with signal' attachment had an error.")
message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA",
@"Message for the alert indicating the 'export with signal' data "
@"couldn't be loaded.")];
return NO;
}
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType];
if (!attachment) { if (!attachment) {
DDLogError(@"Application opened with URL with invalid content: %@", url); DDLogError(@"Application opened with URL with invalid content: %@", url);

@ -126,7 +126,7 @@ NS_ASSUME_NONNULL_BEGIN
self.lastProgress = progress; self.lastProgress = progress;
self.isAttachmentReady = self.attachment.isUploaded; self.isAttachmentReady = self.attachment.isUploaded;
} else { } else {
OWSAssert(0); OWSFail(@"%@ Invalid attachment progress.", self.tag);
self.isAttachmentReady = YES; self.isAttachmentReady = YES;
} }
} }

@ -50,7 +50,7 @@
// With CGImageSource we avoid loading the whole image into memory. // With CGImageSource we avoid loading the whole image into memory.
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL); CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
if (!source) { if (!source) {
OWSAssert(0); OWSFail(@"%@ Could not load image: %@", self.tag, imageURL);
return CGSizeZero; return CGSizeZero;
} }
@ -66,7 +66,7 @@
if (width && height) { if (width && height) {
imageSize = CGSizeMake(width.floatValue, height.floatValue); imageSize = CGSizeMake(width.floatValue, height.floatValue);
} else { } else {
OWSAssert(0); OWSFail(@"%@ Could not determine size of image: %@", self.tag, imageURL);
} }
} }
CFRelease(source); CFRelease(source);

@ -149,22 +149,20 @@ NS_ASSUME_NONNULL_BEGIN
if (action == @selector(copy:)) { if (action == @selector(copy:)) {
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType]; NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType];
if (!utiType) { if (!utiType) {
OWSAssert(0); OWSFail(@"%@ Unknown MIME type: %@", self.tag, self.attachment.contentType);
utiType = (NSString *)kUTTypeGIF; utiType = (NSString *)kUTTypeGIF;
} }
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]]; NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
if (!data) { if (!data) {
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]); OWSFail(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
OWSAssert(0);
return; return;
} }
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
} else if (action == NSSelectorFromString(@"save:")) { } else if (action == NSSelectorFromString(@"save:")) {
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]]; NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
if (!data) { if (!data) {
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]); OWSFail(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
OWSAssert(0);
return; return;
} }
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

@ -267,8 +267,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(utiType.length > 0); OWSAssert(utiType.length > 0);
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL]; NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
if (!data) { if (!data) {
OWSAssert(data); OWSFail(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return; return;
} }
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];

@ -132,7 +132,7 @@ NS_ASSUME_NONNULL_BEGIN
adapter.messageType = TSOutgoingMessageAdapter; adapter.messageType = TSOutgoingMessageAdapter;
} }
} else { } else {
OWSAssert(0); OWSFail(@"%@ Unknown thread type: %@", self.tag, [thread class]);
} }
if ([interaction isKindOfClass:[TSIncomingMessage class]] || if ([interaction isKindOfClass:[TSIncomingMessage class]] ||
@ -235,7 +235,7 @@ NS_ASSUME_NONNULL_BEGIN
adapter.messageBody = errorMessage.description; adapter.messageBody = errorMessage.description;
adapter.messageType = TSErrorMessageAdapter; adapter.messageType = TSErrorMessageAdapter;
} else { } else {
OWSAssert(0); OWSFail(@"%@ Unknown interaction type: %@", self.tag, [interaction class]);
} }
if ([interaction isKindOfClass:[TSOutgoingMessage class]]) { if ([interaction isKindOfClass:[TSOutgoingMessage class]]) {

@ -125,13 +125,12 @@ NS_ASSUME_NONNULL_BEGIN
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType]; NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType];
if (!utiType) { if (!utiType) {
OWSAssert(0); OWSFail(@"%@ Unknown MIME type: %@", self.tag, self.attachment.contentType);
utiType = (NSString *)kUTTypeImage; utiType = (NSString *)kUTTypeImage;
} }
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL]; NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
if (!data) { if (!data) {
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]); OWSFail(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
OWSAssert(0);
return; return;
} }
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
@ -139,8 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
} else if (action == NSSelectorFromString(@"save:")) { } else if (action == NSSelectorFromString(@"save:")) {
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]]; NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
if (!data) { if (!data) {
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]); OWSFail(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
OWSAssert(0);
return; return;
} }
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

@ -211,8 +211,7 @@ NS_ASSUME_NONNULL_BEGIN
[self setAudioIconToPlay]; [self setAudioIconToPlay];
} }
} else { } else {
// Unknown media type. OWSFail(@"%@ Unknown media type: %@", self.tag, self.attachment.contentType);
OWSAssert(0);
} }
return self.cachedMediaView; return self.cachedMediaView;
} }
@ -396,15 +395,14 @@ NS_ASSUME_NONNULL_BEGIN
{ {
if ([self isVideo]) { if ([self isVideo]) {
if (action == @selector(copy:)) { if (action == @selector(copy:)) {
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:_contentType]; NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.contentType];
if (!utiType) { if (!utiType) {
OWSAssert(0); OWSFail(@"%@ Unknown MIME type: %@", self.tag, self.contentType);
utiType = (NSString *)kUTTypeVideo; utiType = (NSString *)kUTTypeVideo;
} }
NSData *data = [NSData dataWithContentsOfURL:self.fileURL]; NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
if (!data) { if (!data) {
OWSAssert(data); OWSFail(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return; return;
} }
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
@ -418,16 +416,15 @@ NS_ASSUME_NONNULL_BEGIN
} }
} else if ([self isAudio]) { } else if ([self isAudio]) {
if (action == @selector(copy:)) { if (action == @selector(copy:)) {
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:_contentType]; NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.contentType];
if (!utiType) { if (!utiType) {
OWSAssert(0); OWSFail(@"%@ Unknown MIME type: %@", self.tag, self.contentType);
utiType = (NSString *)kUTTypeAudio; utiType = (NSString *)kUTTypeAudio;
} }
NSData *data = [NSData dataWithContentsOfURL:self.fileURL]; NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
if (!data) { if (!data) {
OWSAssert(data); OWSFail(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return; return;
} }
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType]; [UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];

@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
__weak AddToBlockListViewController *weakSelf = self; __weak AddToBlockListViewController *weakSelf = self;
ContactsViewHelper *helper = self.contactsViewHelper; ContactsViewHelper *helper = self.contactsViewHelper;
if ([helper isRecipientIdBlocked:signalAccount.recipientId]) { if ([helper isRecipientIdBlocked:signalAccount.recipientId]) {
OWSAssert(0); OWSFail(@"%@ Cannot add already blocked user to block list.", self.tag);
return; return;
} }
[BlockListUIUtils showBlockSignalAccountActionSheet:signalAccount [BlockListUIUtils showBlockSignalAccountActionSheet:signalAccount

@ -99,8 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
__weak AddToGroupViewController *weakSelf = self; __weak AddToGroupViewController *weakSelf = self;
ContactsViewHelper *helper = self.contactsViewHelper; ContactsViewHelper *helper = self.contactsViewHelper;
if ([self.addToGroupDelegate isRecipientGroupMember:signalAccount.recipientId]) { if ([self.addToGroupDelegate isRecipientGroupMember:signalAccount.recipientId]) {
OWSAssert(0); OWSFail(@"%@ Cannot add user to group member if already a member.", self.tag);
return; return;
} }

@ -1346,7 +1346,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
barButtonSize = 105; barButtonSize = 105;
break; break;
default: default:
OWSAssert(0); OWSFail(@"%@ Unexpected number of right navbar items.", self.tag);
// In production, fall through to the largest defined case. // In production, fall through to the largest defined case.
case 2: case 2:
barButtonSize = 150; barButtonSize = 150;
@ -1803,7 +1803,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return self.currentlyOutgoingBubbleImageData; return self.currentlyOutgoingBubbleImageData;
case TSOutgoingMessageStateSent_OBSOLETE: case TSOutgoingMessageStateSent_OBSOLETE:
case TSOutgoingMessageStateDelivered_OBSOLETE: case TSOutgoingMessageStateDelivered_OBSOLETE:
OWSAssert(0); OWSFail(@"%@ Obsolete message state.", self.tag);
return self.outgoingBubbleImageData; return self.outgoingBubbleImageData;
case TSOutgoingMessageStateSentToService: case TSOutgoingMessageStateSentToService:
return self.outgoingBubbleImageData; return self.outgoingBubbleImageData;
@ -1890,8 +1890,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
cellForItemAtIndexPath:indexPath]; cellForItemAtIndexPath:indexPath];
if (![cell isKindOfClass:[OWSIncomingMessageCollectionViewCell class]]) { if (![cell isKindOfClass:[OWSIncomingMessageCollectionViewCell class]]) {
DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell); OWSFail(@"%@ Unexpected cell type: %@", self.tag, cell);
OWSAssert(0);
return cell; return cell;
} }
@ -1911,8 +1910,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
cellForItemAtIndexPath:indexPath]; cellForItemAtIndexPath:indexPath];
if (![cell isKindOfClass:[OWSOutgoingMessageCollectionViewCell class]]) { if (![cell isKindOfClass:[OWSOutgoingMessageCollectionViewCell class]]) {
DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell); OWSFail(@"%@ Unexpected cell type: %@", self.tag, cell);
OWSAssert(0);
return cell; return cell;
} }
@ -3178,21 +3176,15 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
isDirectoryError); isDirectoryError);
} else if ([isDirectory boolValue]) { } else if ([isDirectory boolValue]) {
DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url); DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url);
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE",
@"Alert title when picking a document fails because user picked a directory/bundle")
message:
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY",
@"Alert body when picking a document fails because user picked a directory/bundle")
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissAction =
[UIAlertAction actionWithTitle:CommonStrings.dismissButton style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:dismissAction];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:alertController animated:YES completion:nil]; [OWSAlerts
showAlertWithTitle:
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE",
@"Alert title when picking a document fails because user picked a directory/bundle")
message:
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY",
@"Alert body when picking a document fails because user picked a directory/bundle")];
}); });
return; return;
} }
@ -3207,6 +3199,16 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
OWSAssert(type); OWSAssert(type);
OWSAssert(filename); OWSAssert(filename);
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:url]; id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:url];
if (!dataSource) {
OWSFail(@"%@ attachment data was unexpectedly empty for picked document url: %@", self.tag, url);
dispatch_async(dispatch_get_main_queue(), ^{
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE",
@"Alert title when picking a document fails for an unknown reason")];
});
return;
}
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:type]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:type];
[self tryToSendAttachmentIfApproved:attachment]; [self tryToSendAttachmentIfApproved:attachment];
@ -3293,8 +3295,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[assetslibrary assetForURL:referenceURL [assetslibrary assetForURL:referenceURL
resultBlock:resultblock resultBlock:resultblock
failureBlock:^(NSError *error) { failureBlock:^(NSError *error) {
DDLogError(@"Error retrieving filename for asset: %@", error); OWSFail(@"Error retrieving filename for asset: %@", error);
OWSAssert(0);
}]; }];
} }
@ -3438,24 +3439,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return [NSURL fileURLWithPath:videoDirPath]; return [NSURL fileURLWithPath:videoDirPath];
} }
- (NSUInteger)sizeOfFileURL:(NSURL *)movieURL
{
NSError *error;
NSDictionary<NSFileAttributeKey, id> *_Nullable attributes =
[[NSFileManager defaultManager] attributesOfItemAtPath:movieURL.path error:&error];
OWSAssert(attributes);
OWSAssert(!error);
uint64_t fileSize = [attributes fileSize];
return (NSUInteger)fileSize;
}
- (void)sendQualityAdjustedAttachmentForVideo:(NSURL *)movieURL - (void)sendQualityAdjustedAttachmentForVideo:(NSURL *)movieURL
filename:(NSString *)filename filename:(NSString *)filename
skipApprovalDialog:(BOOL)skipApprovalDialog skipApprovalDialog:(BOOL)skipApprovalDialog
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
DDLogError(@"movieURL: %@ %zd", movieURL, [self sizeOfFileURL:movieURL]);
AVAsset *video = [AVAsset assetWithURL:movieURL]; AVAsset *video = [AVAsset assetWithURL:movieURL];
AVAssetExportSession *exportSession = AVAssetExportSession *exportSession =
[AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality]; [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
@ -3465,7 +3454,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"mp4"]]; URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"mp4"]];
exportSession.outputURL = compressedVideoUrl; exportSession.outputURL = compressedVideoUrl;
[exportSession exportAsynchronouslyWithCompletionHandler:^{ [exportSession exportAsynchronouslyWithCompletionHandler:^{
DDLogError(@"compressedVideoUrl: %@ %zd", compressedVideoUrl, [self sizeOfFileURL:compressedVideoUrl]);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:compressedVideoUrl]; id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:compressedVideoUrl];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];
@ -3769,9 +3757,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
NSError *error; NSError *error;
[session setCategory:AVAudioSessionCategoryRecord error:&error]; [session setCategory:AVAudioSessionCategoryRecord error:&error];
if (error) { if (error) {
DDLogError(@"%@ Couldn't configure audio session: %@", self.tag, error); OWSFail(@"%@ Couldn't configure audio session: %@", self.tag, error);
[self cancelVoiceMemo]; [self cancelVoiceMemo];
OWSAssert(0);
return; return;
} }
@ -3785,25 +3772,22 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
} }
error:&error]; error:&error];
if (error) { if (error) {
DDLogError(@"%@ Couldn't create audioRecorder: %@", self.tag, error); OWSFail(@"%@ Couldn't create audioRecorder: %@", self.tag, error);
[self cancelVoiceMemo]; [self cancelVoiceMemo];
OWSAssert(0);
return; return;
} }
self.audioRecorder.meteringEnabled = YES; self.audioRecorder.meteringEnabled = YES;
if (![self.audioRecorder prepareToRecord]) { if (![self.audioRecorder prepareToRecord]) {
DDLogError(@"%@ audioRecorder couldn't prepareToRecord.", self.tag); OWSFail(@"%@ audioRecorder couldn't prepareToRecord.", self.tag);
[self cancelVoiceMemo]; [self cancelVoiceMemo];
OWSAssert(0);
return; return;
} }
if (![self.audioRecorder record]) { if (![self.audioRecorder record]) {
DDLogError(@"%@ audioRecorder couldn't record.", self.tag); OWSFail(@"%@ audioRecorder couldn't record.", self.tag);
[self cancelVoiceMemo]; [self cancelVoiceMemo];
OWSAssert(0);
return; return;
} }
} }
@ -3847,6 +3831,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:self.audioRecorder.url]; id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:self.audioRecorder.url];
self.audioRecorder = nil; self.audioRecorder = nil;
if (!dataSource) {
OWSFail(@"%@ Couldn't load audioRecorder data", self.tag);
self.audioRecorder = nil;
return;
}
NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.") NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.")
stringByAppendingPathExtension:@"m4a"]; stringByAppendingPathExtension:@"m4a"];
[dataSource setSourceFilename:filename]; [dataSource setSourceFilename:filename];

@ -303,14 +303,12 @@ NS_ASSUME_NONNULL_BEGIN
if ([responseObject writeToFile:filePath atomically:YES]) { if ([responseObject writeToFile:filePath atomically:YES]) {
success(filePath); success(filePath);
} else { } else {
DDLogError(@"Error write url response [%@]: %@", url, filePath); OWSFail(@"Error write url response [%@]: %@", url, filePath);
OWSAssert(0);
failure(); failure();
} }
} }
failure:^(NSURLSessionDataTask *_Nullable task, NSError *requestError) { failure:^(NSURLSessionDataTask *_Nullable task, NSError *requestError) {
DDLogError(@"Error downloading url[%@]: %@", url, requestError); OWSFail(@"Error downloading url[%@]: %@", url, requestError);
OWSAssert(0);
failure(); failure();
}]; }];
} }

@ -915,8 +915,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(!self.isGroupThread); OWSAssert(!self.isGroupThread);
if (![sender isKindOfClass:[UISwitch class]]) { if (![sender isKindOfClass:[UISwitch class]]) {
DDLogError(@"%@ Unexpected sender for block user switch: %@", self.tag, sender); OWSFail(@"%@ Unexpected sender for block user switch: %@", self.tag, sender);
OWSAssert(0);
} }
UISwitch *blockUserSwitch = (UISwitch *)sender; UISwitch *blockUserSwitch = (UISwitch *)sender;

@ -285,8 +285,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
OWSAssert(self.delegate); OWSAssert(self.delegate);
if (![self hasValidPhoneNumber]) { if (![self hasValidPhoneNumber]) {
DDLogError(@"Invalid phone number was selected."); OWSFail(@"Invalid phone number was selected.");
OWSAssert(0);
return; return;
} }
@ -299,8 +298,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[possiblePhoneNumbers addObject:phoneNumber.toE164]; [possiblePhoneNumbers addObject:phoneNumber.toE164];
} }
if ([possiblePhoneNumbers count] < 1) { if ([possiblePhoneNumbers count] < 1) {
DDLogError(@"Couldn't parse phone number."); OWSFail(@"Couldn't parse phone number.");
OWSAssert(0);
return; return;
} }

@ -340,7 +340,7 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
if (self.cachedAccountNameMap || self.cachedFirstNameMap || self.cachedLastNameMap) { if (self.cachedAccountNameMap || self.cachedFirstNameMap || self.cachedLastNameMap) {
// If these properties have already been populated from system contacts, // If these properties have already been populated from system contacts,
// don't overwrite. In practice this should never happen. // don't overwrite. In practice this should never happen.
OWSAssert(0); OWSFail(@"%@ Unexpected cache state", self.tag);
return; return;
} }

@ -201,8 +201,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(errorMessage.errorType == TSErrorMessageNonBlockingIdentityChange); OWSAssert(errorMessage.errorType == TSErrorMessageNonBlockingIdentityChange);
[nonBlockingSafetyNumberChanges addObject:errorMessage]; [nonBlockingSafetyNumberChanges addObject:errorMessage];
} else { } else {
DDLogError(@"Unexpected dynamic interaction type: %@", [object class]); OWSFail(@"Unexpected dynamic interaction type: %@", [object class]);
OWSAssert(0);
} }
}]; }];

@ -263,8 +263,10 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
} else { } else {
SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:currentSignedPrekeyId.intValue]; SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:currentSignedPrekeyId.intValue];
if (!currentRecord) { if (!currentRecord) {
DDLogError(@"%@ %s Couldn't find signed prekey for id: %@", self.tag, __PRETTY_FUNCTION__, currentSignedPrekeyId); OWSFail(@"%@ %s Couldn't find signed prekey for id: %@",
OWSAssert(0); self.tag,
__PRETTY_FUNCTION__,
currentSignedPrekeyId);
shouldUpdateSignedPrekey = YES; shouldUpdateSignedPrekey = YES;
} else { } else {
shouldUpdateSignedPrekey shouldUpdateSignedPrekey
@ -352,8 +354,7 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
TSStorageManager *storageManager = [TSStorageManager sharedManager]; TSStorageManager *storageManager = [TSStorageManager sharedManager];
SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:keyId.intValue]; SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:keyId.intValue];
if (!currentRecord) { if (!currentRecord) {
DDLogError(@"%@ %s Couldn't find signed prekey for id: %@", self.tag, __PRETTY_FUNCTION__, keyId); OWSFail(@"%@ %s Couldn't find signed prekey for id: %@", self.tag, __PRETTY_FUNCTION__, keyId);
OWSAssert(0);
} }
NSArray *allSignedPrekeys = [storageManager loadSignedPreKeys]; NSArray *allSignedPrekeys = [storageManager loadSignedPreKeys];
NSArray *oldSignedPrekeys NSArray *oldSignedPrekeys

@ -171,13 +171,11 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
// downloading attachments with low server ids". // downloading attachments with low server ids".
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
NSInteger statusCode = [httpResponse statusCode]; NSInteger statusCode = [httpResponse statusCode];
DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@", OWSFail(@"%@ %d Failure with suspicious attachment id: %llu, %@",
self.tag, self.tag,
(int)statusCode, (int)statusCode,
(unsigned long long)attachment.serverId, (unsigned long long)attachment.serverId,
error); error);
[DDLog flushLog];
OWSAssert(0);
} }
if (markAndHandleFailure) { if (markAndHandleFailure) {
markAndHandleFailure(error); markAndHandleFailure(error);
@ -195,13 +193,11 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
// downloading attachments with low server ids". // downloading attachments with low server ids".
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
NSInteger statusCode = [httpResponse statusCode]; NSInteger statusCode = [httpResponse statusCode];
DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@", OWSFail(@"%@ %d Failure with suspicious attachment id: %llu, %@",
self.tag, self.tag,
(int)statusCode, (int)statusCode,
(unsigned long long)attachment.serverId, (unsigned long long)attachment.serverId,
error); error);
[DDLog flushLog];
OWSAssert(0);
} }
return markAndHandleFailure(error); return markAndHandleFailure(error);
}]; }];
@ -258,12 +254,12 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
if (progress.completedUnitCount < 1) { if (progress.completedUnitCount < 1) {
return; return;
} }
void (^abortDownload)() = ^{ void (^abortDownload)() = ^{
OWSAssert(0); OWSFail(@"%@ Download aborted.", self.tag);
[task cancel]; [task cancel];
}; };
if (progress.totalUnitCount > kMaxDownloadSize || progress.completedUnitCount > kMaxDownloadSize) { if (progress.totalUnitCount > kMaxDownloadSize || progress.completedUnitCount > kMaxDownloadSize) {
// A malicious service might send a misleading content length header, // A malicious service might send a misleading content length header,
// so.... // so....

@ -114,19 +114,16 @@ NS_ASSUME_NONNULL_BEGIN
sourceFilename:self.sourceFilename sourceFilename:self.sourceFilename
inFolder:attachmentsFolder]; inFolder:attachmentsFolder];
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Could not generate path for attachment.", self.tag); OWSFail(@"%@ Could not generate path for attachment.", self.tag);
OWSAssert(0);
return; return;
} }
if (![filePath hasPrefix:attachmentsFolder]) { if (![filePath hasPrefix:attachmentsFolder]) {
DDLogError(@"%@ Attachment paths should all be in the attachments folder.", self.tag); OWSFail(@"%@ Attachment paths should all be in the attachments folder.", self.tag);
OWSAssert(0);
return; return;
} }
NSString *localRelativeFilePath = [filePath substringFromIndex:attachmentsFolder.length]; NSString *localRelativeFilePath = [filePath substringFromIndex:attachmentsFolder.length];
if (localRelativeFilePath.length < 1) { if (localRelativeFilePath.length < 1) {
DDLogError(@"%@ Empty local relative attachment paths.", self.tag); OWSFail(@"%@ Empty local relative attachment paths.", self.tag);
OWSAssert(0);
return; return;
} }
@ -141,8 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
*error = nil; *error = nil;
NSString *_Nullable filePath = self.filePath; NSString *_Nullable filePath = self.filePath;
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Missing path for attachment.", self.tag); OWSFail(@"%@ Missing path for attachment.", self.tag);
OWSAssert(0);
return nil; return nil;
} }
return [NSData dataWithContentsOfFile:filePath options:0 error:error]; return [NSData dataWithContentsOfFile:filePath options:0 error:error];
@ -155,8 +151,7 @@ NS_ASSUME_NONNULL_BEGIN
*error = nil; *error = nil;
NSString *_Nullable filePath = self.filePath; NSString *_Nullable filePath = self.filePath;
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Missing path for attachment.", self.tag); OWSFail(@"%@ Missing path for attachment.", self.tag);
OWSAssert(0);
return NO; return NO;
} }
DDLogInfo(@"%@ Writing attachment to file: %@", self.tag, filePath); DDLogInfo(@"%@ Writing attachment to file: %@", self.tag, filePath);
@ -169,8 +164,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *_Nullable filePath = self.filePath; NSString *_Nullable filePath = self.filePath;
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Missing path for attachment.", self.tag); OWSFail(@"%@ Missing path for attachment.", self.tag);
OWSAssert(0);
return NO; return NO;
} }
DDLogInfo(@"%@ Writing attachment to file: %@", self.tag, filePath); DDLogInfo(@"%@ Writing attachment to file: %@", self.tag, filePath);
@ -209,7 +203,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSString *)filePath - (nullable NSString *)filePath
{ {
if (!self.localRelativeFilePath) { if (!self.localRelativeFilePath) {
OWSAssert(0); OWSFail(@"%@ Attachment missing local file path.", self.tag);
return nil; return nil;
} }
@ -220,8 +214,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
NSString *_Nullable filePath = self.filePath; NSString *_Nullable filePath = self.filePath;
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Missing path for attachment.", self.tag); OWSFail(@"%@ Missing path for attachment.", self.tag);
OWSAssert(0);
return nil; return nil;
} }
return [NSURL fileURLWithPath:filePath]; return [NSURL fileURLWithPath:filePath];
@ -231,8 +224,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
NSString *_Nullable filePath = self.filePath; NSString *_Nullable filePath = self.filePath;
if (!filePath) { if (!filePath) {
DDLogError(@"%@ Missing path for attachment.", self.tag); OWSFail(@"%@ Missing path for attachment.", self.tag);
OWSAssert(0);
return; return;
} }
NSError *error; NSError *error;
@ -342,7 +334,7 @@ NS_ASSUME_NONNULL_BEGIN
// With CGImageSource we avoid loading the whole image into memory. // With CGImageSource we avoid loading the whole image into memory.
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)mediaUrl, NULL); CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)mediaUrl, NULL);
if (!source) { if (!source) {
OWSAssert(0); OWSFail(@"%@ Could not load image: %@", self.tag, mediaUrl);
return CGSizeZero; return CGSizeZero;
} }
@ -358,7 +350,7 @@ NS_ASSUME_NONNULL_BEGIN
if (width && height) { if (width && height) {
imageSize = CGSizeMake(width.floatValue, height.floatValue); imageSize = CGSizeMake(width.floatValue, height.floatValue);
} else { } else {
OWSAssert(0); OWSFail(@"%@ Could not determine size of image: %@", self.tag, mediaUrl);
} }
} }
CFRelease(source); CFRelease(source);
@ -391,7 +383,7 @@ NS_ASSUME_NONNULL_BEGIN
[latestInstance saveWithTransaction:transaction]; [latestInstance saveWithTransaction:transaction];
} else { } else {
// This message has not yet been saved; do nothing. // This message has not yet been saved; do nothing.
OWSAssert(0); OWSFail(@"%@ Attachment not yet saved.", self.tag);
} }
}; };
@ -462,7 +454,7 @@ NS_ASSUME_NONNULL_BEGIN
[latestInstance saveWithTransaction:transaction]; [latestInstance saveWithTransaction:transaction];
} else { } else {
// This message has not yet been saved; do nothing. // This message has not yet been saved; do nothing.
OWSAssert(0); OWSFail(@"%@ Attachment not yet saved.", self.tag);
} }
}; };

@ -219,7 +219,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
return NO; return NO;
case TSOutgoingMessageStateSent_OBSOLETE: case TSOutgoingMessageStateSent_OBSOLETE:
case TSOutgoingMessageStateDelivered_OBSOLETE: case TSOutgoingMessageStateDelivered_OBSOLETE:
OWSAssert(0); OWSFail(@"%@ Obsolete message state.", self.tag);
return self.isExpiringMessage; return self.isExpiringMessage;
} }
} }

@ -363,7 +363,7 @@ NS_ASSUME_NONNULL_BEGIN
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
// Don't run when inactive. // Don't run when inactive.
OWSAssert(0); OWSFail(@"%@ Disappearing messages job timer fired while app inactive.", self.tag);
return; return;
} }

@ -324,8 +324,7 @@ NSString *const kSyncMessageFileExtension = @"bin";
attributes:nil attributes:nil
error:&error]; error:&error];
if (error) { if (error) {
DDLogError(@"Failed to create attachment directory: %@", error); OWSFail(@"Failed to create attachment directory: %@", error);
OWSAssert(0);
return nil; return nil;
} }
} }

@ -375,7 +375,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
logFlag = DDLogFlagError; logFlag = DDLogFlagError;
break; break;
default: default:
OWSAssert(0); OWSFail(@"Unknown severity.");
logFlag = DDLogFlagDebug; logFlag = DDLogFlagDebug;
break; break;
} }

Loading…
Cancel
Save