Exception audit, fail directly where intended

pull/1/head
Michael Kirk 7 years ago
parent 9d2731c9b8
commit c686e766b1

@ -30,7 +30,7 @@
- (instancetype)init
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method");
OWSFail(@"You must use the initWithURL: method");
return nil;
}
@ -41,7 +41,7 @@
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method");
OWSFail(@"You must use the initWithURL: method");
return nil;
}

@ -152,13 +152,11 @@ NSString *const OWSCensorshipConfiguration_DefaultFrontingHost = OWSCensorshipCo
NSError *error;
NSData *certData = [self certificateDataWithName:certName error:&error];
if (error) {
OWSLogError(@"reading data for certificate: %@ failed with error: %@", certName, error);
OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", @"%@", error.description);
OWSFail(@"reading data for certificate: %@ failed with error: %@", certName, error);
}
if (!certData) {
OWSLogError(@"No data for certificate: %@", certName);
OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", @"%@", error.description);
OWSFail(@"reading data for certificate: %@ failed with error: %@", certName, error);
}
[certificates addObject:certData];
}

@ -43,7 +43,7 @@
NSString *path = [bundle pathForResource:service ofType:@"cer"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
OWSRaiseException(@"Missing server certificate", @"Missing signing certificate for service %@", service);
OWSFail(@"Missing signing certificate for service %@", service);
}
NSData *certificateData = [NSData dataWithContentsOfFile:path];

@ -28,8 +28,6 @@ NSString *const OWSUIDatabaseConnectionWillUpdateExternallyNotification = @"OWSU
NSString *const OWSUIDatabaseConnectionDidUpdateExternallyNotification = @"OWSUIDatabaseConnectionDidUpdateExternallyNotification";
NSString *const OWSUIDatabaseConnectionNotificationsKey = @"OWSUIDatabaseConnectionNotificationsKey";
NSString *const OWSPrimaryStorageExceptionName_CouldNotCreateDatabaseDirectory
= @"TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory";
void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
{
@ -252,8 +250,7 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"];
if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) {
OWSRaiseException(
OWSPrimaryStorageExceptionName_CouldNotCreateDatabaseDirectory, @"Could not create new database directory");
OWSFail(@"Could not create new database directory");
}
return databaseDirPath;
}

@ -26,12 +26,6 @@
NS_ASSUME_NONNULL_BEGIN
NSString *const StorageIsReadyNotification = @"StorageIsReadyNotification";
NSString *const OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded
= @"OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded";
NSString *const OWSStorageExceptionName_DatabasePasswordUnwritable
= @"OWSStorageExceptionName_DatabasePasswordUnwritable";
NSString *const OWSStorageExceptionName_NoDatabase = @"OWSStorageExceptionName_NoDatabase";
NSString *const OWSResetStorageNotification = @"OWSResetStorageNotification";
static NSString *keychainService = @"TSKeyChainService";
@ -330,7 +324,7 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f];
OWSRaiseException(OWSStorageExceptionName_NoDatabase, @"Failed to initialize database.");
OWSFail(@"Failed to initialize database.");
}
}
}
@ -503,8 +497,7 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
{
YapDatabaseConnection *dbConnection = self.database.newConnection;
if (!dbConnection) {
OWSRaiseException(
@"OWSStorageExceptionName_CouldNotOpenConnection", @"Storage could not open new database connection.");
OWSFail(@"Storage could not open new database connection.");
}
return dbConnection;
}
@ -862,7 +855,7 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// Presumably this happened in response to a push notification. It's possible that the keychain is corrupted
// but it could also just be that the user hasn't yet unlocked their device since our password is
// kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
OWSRaiseException(OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded, @"%@", errorDescription);
OWSFail(@"%@", errorDescription);
}
+ (void)deleteDBKeys
@ -925,8 +918,7 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f];
OWSRaiseException(
OWSStorageExceptionName_DatabasePasswordUnwritable, @"Setting keychain value failed with error: %@", error);
OWSFail(@"Setting keychain value failed with error: %@", error);
} else {
OWSLogWarn(@"Successfully set new keychain value.");
}

@ -138,7 +138,8 @@
break;
default:
OWSRaiseException(NSInternalInconsistencyException, @"Invalid image orientation");
OWSFailDebug(@"Invalid image orientation");
return nil;
}
/////////////////////////////////////////////////////////////////////////////

Loading…
Cancel
Save