Skip to content

Commit 1b696b1

Browse files
morganchen12leotianlizhan
authored andcommitted
Improve error logging when table creation fails (#8699)
* Improve error logging when table creation fails * add changelog * style
1 parent 53e0f6a commit 1b696b1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

FirebaseMessaging/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Improved reporting for SQLite errors when failing to open a local database (#8699).
3+
14
# 2021-08 -- v8.11.0
25
- [fixed] Fixed an issue that token is not associated with APNS token during app start. (#8738)
36

FirebaseMessaging/Sources/FIRMessagingRmqManager.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,21 @@ + (NSString *)pathForDatabaseWithName:(NSString *)databaseName {
443443

444444
- (void)createTableWithName:(NSString *)tableName command:(NSString *)command {
445445
FIRMessaging_MUST_NOT_BE_MAIN_THREAD();
446-
char *error;
446+
char *error = NULL;
447447
NSString *createDatabase = [NSString stringWithFormat:command, kTablePrefix, tableName];
448448
if (sqlite3_exec(self->_database, [createDatabase UTF8String], NULL, NULL, &error) != SQLITE_OK) {
449449
// remove db before failing
450450
[self removeDatabase];
451-
NSString *errorMessage = [NSString
452-
stringWithFormat:@"Couldn't create table: %@ %@", kCreateTableOutgoingRmqMessages,
453-
[NSString stringWithCString:error encoding:NSUTF8StringEncoding]];
451+
NSString *sqlError;
452+
if (error != NULL) {
453+
sqlError = [NSString stringWithCString:error encoding:NSUTF8StringEncoding];
454+
sqlite3_free(error);
455+
} else {
456+
sqlError = @"(null)";
457+
}
458+
NSString *errorMessage =
459+
[NSString stringWithFormat:@"Couldn't create table: %@ with command: %@ error: %@",
460+
kCreateTableOutgoingRmqMessages, createDatabase, sqlError];
454461
FIRMessagingLoggerError(kFIRMessagingMessageCodeRmq2PersistentStoreErrorCreatingTable, @"%@",
455462
errorMessage);
456463
NSAssert(NO, errorMessage);

0 commit comments

Comments
 (0)