Fix FileBasedFaviconPersister FileAlreadyExistsException#8030
Merged
Fix FileBasedFaviconPersister FileAlreadyExistsException#8030
Conversation
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Silent exception swallowing masks all copy failures
- Replaced broad runCatching with explicit exception handling that logs copy failures and only catches Exception instead of all Throwable.
Or push these changes by commenting:
@cursor push a8b051c7d9
Preview (a8b051c7d9)
diff --git a/app/src/main/java/com/duckduckgo/app/browser/favicon/FaviconPersister.kt b/app/src/main/java/com/duckduckgo/app/browser/favicon/FaviconPersister.kt
--- a/app/src/main/java/com/duckduckgo/app/browser/favicon/FaviconPersister.kt
+++ b/app/src/main/java/com/duckduckgo/app/browser/favicon/FaviconPersister.kt
@@ -27,6 +27,7 @@
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
+import logcat.LogPriority.ERROR
import logcat.LogPriority.INFO
import logcat.logcat
import java.io.File
@@ -96,7 +97,17 @@
) {
withContext(dispatcherProvider.io()) {
val persistedFile = fileForFavicon(directory, newSubfolder, newFilename)
- runCatching { file.copyTo(persistedFile, overwrite = true) }
+ try {
+ file.copyTo(persistedFile, overwrite = true)
+ } catch (exception: FileAlreadyExistsException) {
+ logcat(INFO, exception) {
+ "Favicon destination already exists and could not be replaced: ${persistedFile.absolutePath}"
+ }
+ } catch (exception: Exception) {
+ logcat(ERROR, exception) {
+ "Failed to persist favicon to ${persistedFile.absolutePath}"
+ }
+ }
}
}
app/src/main/java/com/duckduckgo/app/browser/favicon/FaviconPersister.kt
Outdated
Show resolved
Hide resolved
2789592 to
83e0169
Compare
karlenDimla
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Task/Issue URL: https://app.asana.com/1/137249556945/project/1200204095367872/task/1213736584422142?focus=true
Description
FileAlreadyExistsExceptionifcopyTothrowsSteps to test this PR
Note
Low Risk
Low risk: wraps a single file copy operation to avoid crashing when copy fails (e.g., existing destination/race), with no behavioral changes elsewhere.
Overview
Prevents crashes when persisting favicons by wrapping
FileBasedFaviconPersister.copyToDirectory’sfile.copyTo(...)call inrunCatching, effectively swallowingFileAlreadyExistsException/IO failures during the copy.Written by Cursor Bugbot for commit 2789592. This will update automatically on new commits. Configure here.