[fenix] fix fenix crashing when trying to add an invalid bookmark

pull/600/head
Sammy Khamis 3 years ago committed by mergify[bot]
parent 8cfc336a55
commit caabbcc848

@ -39,6 +39,7 @@ import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.appservices.places.BookmarkRoot
import mozilla.appservices.places.uniffi.PlacesException
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
@ -1230,6 +1231,7 @@ abstract class BaseBrowserFragment :
}
} else {
// Save bookmark, then go to edit fragment
try {
val guid = bookmarksStorage.addItem(
BookmarkRoot.Mobile.id,
url = sessionUrl,
@ -1259,6 +1261,9 @@ abstract class BaseBrowserFragment :
.show()
}
}
} catch (e: PlacesException.UrlParseFailed) {
println("We should do something here")
}
}
}

@ -6,6 +6,7 @@ package org.mozilla.fenix.components.bookmarks
import androidx.annotation.WorkerThread
import mozilla.appservices.places.BookmarkRoot
import mozilla.appservices.places.uniffi.PlacesException
import mozilla.components.concept.storage.BookmarksStorage
import mozilla.components.concept.storage.HistoryStorage
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
@ -29,6 +30,7 @@ class BookmarksUseCase(
*/
@WorkerThread
suspend operator fun invoke(url: String, title: String, position: UInt? = null): Boolean {
try {
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == it.url } == null
if (canAdd) {
@ -39,8 +41,10 @@ class BookmarksUseCase(
position = position
)
}
return canAdd
} catch (e: PlacesException.UrlParseFailed) {
return false
}
}
}

Loading…
Cancel
Save