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];
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];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType];
if (!attachment) {
DDLogError(@"Application opened with URL with invalid content: %@", url);

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

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

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

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

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

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

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

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

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

@ -1346,7 +1346,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
barButtonSize = 105;
break;
default:
OWSAssert(0);
OWSFail(@"%@ Unexpected number of right navbar items.", self.tag);
// In production, fall through to the largest defined case.
case 2:
barButtonSize = 150;
@ -1803,7 +1803,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return self.currentlyOutgoingBubbleImageData;
case TSOutgoingMessageStateSent_OBSOLETE:
case TSOutgoingMessageStateDelivered_OBSOLETE:
OWSAssert(0);
OWSFail(@"%@ Obsolete message state.", self.tag);
return self.outgoingBubbleImageData;
case TSOutgoingMessageStateSentToService:
return self.outgoingBubbleImageData;
@ -1890,8 +1890,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
cellForItemAtIndexPath:indexPath];
if (![cell isKindOfClass:[OWSIncomingMessageCollectionViewCell class]]) {
DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell);
OWSAssert(0);
OWSFail(@"%@ Unexpected cell type: %@", self.tag, cell);
return cell;
}
@ -1911,8 +1910,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
cellForItemAtIndexPath:indexPath];
if (![cell isKindOfClass:[OWSOutgoingMessageCollectionViewCell class]]) {
DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell);
OWSAssert(0);
OWSFail(@"%@ Unexpected cell type: %@", self.tag, cell);
return cell;
}
@ -3178,21 +3176,15 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
isDirectoryError);
} else if ([isDirectory boolValue]) {
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(), ^{
[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;
}
@ -3207,6 +3199,16 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
OWSAssert(type);
OWSAssert(filename);
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];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:type];
[self tryToSendAttachmentIfApproved:attachment];
@ -3293,8 +3295,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[assetslibrary assetForURL:referenceURL
resultBlock:resultblock
failureBlock:^(NSError *error) {
DDLogError(@"Error retrieving filename for asset: %@", error);
OWSAssert(0);
OWSFail(@"Error retrieving filename for asset: %@", error);
}];
}
@ -3438,24 +3439,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
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
filename:(NSString *)filename
skipApprovalDialog:(BOOL)skipApprovalDialog
{
OWSAssert([NSThread isMainThread]);
DDLogError(@"movieURL: %@ %zd", movieURL, [self sizeOfFileURL:movieURL]);
AVAsset *video = [AVAsset assetWithURL:movieURL];
AVAssetExportSession *exportSession =
[AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
@ -3465,7 +3454,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"mp4"]];
exportSession.outputURL = compressedVideoUrl;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
DDLogError(@"compressedVideoUrl: %@ %zd", compressedVideoUrl, [self sizeOfFileURL:compressedVideoUrl]);
dispatch_async(dispatch_get_main_queue(), ^{
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:compressedVideoUrl];
[dataSource setSourceFilename:filename];
@ -3769,9 +3757,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
NSError *error;
[session setCategory:AVAudioSessionCategoryRecord error:&error];
if (error) {
DDLogError(@"%@ Couldn't configure audio session: %@", self.tag, error);
OWSFail(@"%@ Couldn't configure audio session: %@", self.tag, error);
[self cancelVoiceMemo];
OWSAssert(0);
return;
}
@ -3785,25 +3772,22 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
}
error:&error];
if (error) {
DDLogError(@"%@ Couldn't create audioRecorder: %@", self.tag, error);
OWSFail(@"%@ Couldn't create audioRecorder: %@", self.tag, error);
[self cancelVoiceMemo];
OWSAssert(0);
return;
}
self.audioRecorder.meteringEnabled = YES;
if (![self.audioRecorder prepareToRecord]) {
DDLogError(@"%@ audioRecorder couldn't prepareToRecord.", self.tag);
OWSFail(@"%@ audioRecorder couldn't prepareToRecord.", self.tag);
[self cancelVoiceMemo];
OWSAssert(0);
return;
}
if (![self.audioRecorder record]) {
DDLogError(@"%@ audioRecorder couldn't record.", self.tag);
OWSFail(@"%@ audioRecorder couldn't record.", self.tag);
[self cancelVoiceMemo];
OWSAssert(0);
return;
}
}
@ -3847,6 +3831,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
id<DataSource> _Nullable dataSource = [DataSourcePath dataSourceWithURL:self.audioRecorder.url];
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.")
stringByAppendingPathExtension:@"m4a"];
[dataSource setSourceFilename:filename];

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save