-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remove FIRMessaging_FAIL macro, log result code #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,14 @@ | |
// table data handlers | ||
typedef void(^FCMOutgoingRmqMessagesTableHandler)(int64_t rmqId, int8_t tag, NSData *data); | ||
|
||
// Utility to create an NSString from a sqlite3 result code | ||
NSString * _Nonnull FIRMessagingStringFromSQLiteResult(int result) { | ||
const char *errorStr = sqlite3_errstr(result); | ||
//NSString *errorString = [NSString stringWithCString:errorStr encoding:NSUTF8StringEncoding]; | ||
NSString *errorString = [NSString stringWithFormat:@"%d - %s", result, errorStr]; | ||
return errorString; | ||
} | ||
|
||
@interface FIRMessagingRmq2PersistentStore () { | ||
sqlite3 *_database; | ||
} | ||
|
@@ -187,6 +195,7 @@ + (NSString *)pathForDatabase:(NSString *)dbName inDirectory:(FIRMessagingRmqDir | |
NSArray *paths; | ||
NSArray *components; | ||
NSString *dbNameWithExtension = [NSString stringWithFormat:@"%@.sqlite", dbName]; | ||
NSString *errorMessage; | ||
|
||
switch (directory) { | ||
case FIRMessagingRmqDirectoryDocuments: | ||
|
@@ -206,7 +215,11 @@ + (NSString *)pathForDatabase:(NSString *)dbName inDirectory:(FIRMessagingRmqDir | |
break; | ||
|
||
default: | ||
FIRMessaging_FAIL(@"Invalid directory type %zd", directory); | ||
errorMessage = [NSString stringWithFormat:@"Invalid directory type %zd", directory]; | ||
FIRMessagingLoggerError(kFIRMessagingMessageCodeRmq2PersistentStoreInvalidRmqDirectory, | ||
@"%@", | ||
errorMessage); | ||
NSAssert(NO, errorMessage); | ||
break; | ||
} | ||
|
||
|
@@ -219,9 +232,13 @@ - (void)createTableWithName:(NSString *)tableName command:(NSString *)command { | |
if (sqlite3_exec(_database, [createDatabase UTF8String], NULL, NULL, &error) != SQLITE_OK) { | ||
// remove db before failing | ||
[self removeDatabase]; | ||
FIRMessaging_FAIL(@"Couldn't create table: %@ %@", | ||
kCreateTableOutgoingRmqMessages, | ||
[NSString stringWithCString:error encoding:NSUTF8StringEncoding]); | ||
NSString *errorMessage = [NSString stringWithFormat:@"Couldn't create table: %@ %@", | ||
kCreateTableOutgoingRmqMessages, | ||
[NSString stringWithCString:error encoding:NSUTF8StringEncoding]]; | ||
FIRMessagingLoggerError(kFIRMessagingMessageCodeRmq2PersistentStoreErrorCreatingTable, | ||
@"%@", | ||
errorMessage); | ||
NSAssert(NO, errorMessage); | ||
} | ||
} | ||
|
||
|
@@ -256,8 +273,17 @@ - (void)openDatabase:(NSString *)dbName { | |
BOOL didOpenDatabase = YES; | ||
if (![fileManager fileExistsAtPath:path]) { | ||
// We've to separate between different versions here because of backwards compatbility issues. | ||
if (sqlite3_open([path UTF8String], &_database) != SQLITE_OK) { | ||
FIRMessaging_FAIL(@"%@ Could not open rmq database: %@", kFCMRmqStoreTag, path); | ||
int result = sqlite3_open([path UTF8String], &_database); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the next two blocks exactly match, probably should be factored into a function for code size and readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, agreed. Just didn't want to change a larger block of code this close to release 😄 |
||
if (result != SQLITE_OK) { | ||
NSString *errorString = FIRMessagingStringFromSQLiteResult(result); | ||
NSString *errorMessage = | ||
[NSString stringWithFormat:@"Could not open existing RMQ database at path %@, error: %@", | ||
path, | ||
errorString]; | ||
FIRMessagingLoggerError(kFIRMessagingMessageCodeRmq2PersistentStoreErrorOpeningDatabase, | ||
@"%@", | ||
errorMessage); | ||
NSAssert(NO, errorMessage); | ||
didOpenDatabase = NO; | ||
return; | ||
} | ||
|
@@ -267,8 +293,18 @@ - (void)openDatabase:(NSString *)dbName { | |
[self createTableWithName:kTableLastRmqId command:kCreateTableLastRmqId]; | ||
[self createTableWithName:kTableS2DRmqIds command:kCreateTableS2DRmqIds]; | ||
} else { | ||
if (sqlite3_open([path UTF8String], &_database) != SQLITE_OK) { | ||
FIRMessaging_FAIL(@"%@ Could not open rmq database: %@", kFCMRmqStoreTag, path); | ||
// Calling sqlite3_open should create the database, since the file doesn't exist. | ||
int result = sqlite3_open([path UTF8String], &_database); | ||
if (result != SQLITE_OK) { | ||
NSString *errorString = FIRMessagingStringFromSQLiteResult(result); | ||
NSString *errorMessage = | ||
[NSString stringWithFormat:@"Could not create RMQ database at path %@, error: %@", | ||
path, | ||
errorString]; | ||
FIRMessagingLoggerError(kFIRMessagingMessageCodeRmq2PersistentStoreErrorCreatingDatabase, | ||
@"%@", | ||
errorMessage); | ||
NSAssert(NO, errorMessage); | ||
didOpenDatabase = NO; | ||
} else { | ||
[self updateDbWithStringRmqID]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented line can probably be removed. But out of curiosity, why use a format instead of creating an NSString from the C string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Commented-out line removed. The main reason for going with the format was because I want to show it as "
resultCode
-errorMsg
". UsinginitWithCString
I'd end up creating a string with format anyway.