Handle SQLite corruption during database initialization

GRDB executes some simple statements when initializing a `DatabasePool`
object (see [1][], [2][], [3][], [4][]). If any of those fail with a
corruption error, we should flag the database as corrupted. This will
let the user attempt recovery.

[1]: 23f4254ae3/GRDB/Core/Database.swift (L365)
[2]: 23f4254ae3/GRDB/Core/DatabasePool.swift (L75)
[3]: 23f4254ae3/GRDB/Core/DatabasePool.swift (L82)
[4]: 23f4254ae3/GRDB/Core/DatabasePool.swift (L91-L94)
This commit is contained in:
Evan Hahn 2022-12-19 13:15:05 -06:00 committed by Evan Hahn
parent fb8f390733
commit dc9637b127

View File

@ -110,6 +110,10 @@ public class GRDBDatabaseStorageAdapter: NSObject {
// Crash if storage can't be initialized.
storage = try GRDBStorage(dbURL: databaseFileUrl, keyspec: GRDBDatabaseStorageAdapter.keyspec)
} catch {
DatabaseCorruptionState.flagDatabaseCorruptionIfNecessary(
userDefaults: CurrentAppContext().appUserDefaults(),
error: error
)
owsFail("\(error.grdbErrorForLogging)")
}