Skip to content

Commit

Permalink
try-catch SQLiteDiskIOException (#4407)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/488551667048375/1207030969079654/f

### Description
add catch when creating bloomfilter to avoid crashing the app is something goes wrong with DB

### Steps to test this PR
QA optional
  • Loading branch information
aitorvs authored and marcosholgado committed Apr 10, 2024
1 parent ddfeaf3 commit ca825b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/com/duckduckgo/app/global/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ class MigrationsProvider(val context: Context, val settingsDataStore: SettingsDa
}
}

/**
* WARNING ⚠️
* This needs to happen because Room doesn't support UNIQUE (...) ON CONFLICT REPLACE when creating the bookmarks table.
* When updating the bookmarks table, you will need to update this creation script in order to properly maintain the above
* constraint.
*/
val BOOKMARKS_DB_ON_CREATE = object : RoomDatabase.Callback() {
override fun onCreate(database: SupportSQLiteDatabase) {
database.execSQL(
Expand All @@ -672,12 +678,6 @@ class MigrationsProvider(val context: Context, val settingsDataStore: SettingsDa
}
}

/**
* WARNING ⚠️
* This needs to happen because Room doesn't support UNIQUE (...) ON CONFLICT REPLACE when creating the bookmarks table.
* When updating the bookmarks table, you will need to update this creation script in order to properly maintain the above
* constraint.
*/
val CHANGE_JOURNAL_ON_OPEN = object : RoomDatabase.Callback() {
override fun onOpen(db: SupportSQLiteDatabase) {
db.query("PRAGMA journal_mode=DELETE;").use { cursor -> cursor.moveToFirst() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ class HttpsUpgraderImpl @Inject constructor(
override fun reloadData() {
logcat { "Reload Https upgrader data" }
bloomReloadLock.lock()
try {
bloomFilter = bloomFactory.create()
} finally {
bloomReloadLock.unlock()
}
bloomFilter = runCatching { bloomFactory.create() }.getOrNull()
bloomReloadLock.unlock()
}

private fun waitForAnyReloadsToComplete() {
Expand Down

0 comments on commit ca825b7

Please sign in to comment.