Skip to content

Commit

Permalink
Catch URISyntaxException in optionalURL
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Jan 23, 2025
1 parent ea92cf0 commit f2b2b38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.capyreader.app.notifications.Notifications
import com.capyreader.app.R
import com.capyreader.app.common.notificationManager
import com.capyreader.app.notifications.Notifications
import com.jocmp.capy.Account
import com.jocmp.capy.logging.CapyLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -54,6 +55,7 @@ class OPMLImportWorker(

showToast(R.string.opml_import_toast_complete)
} catch (e: Throwable) {
CapyLog.error("importer", e)
showToast(R.string.opml_import_toast_failed)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ internal class LocalAccountDelegate(
CapyLog.warn(
tag("find"),
data = mapOf(
"error_message" to response.exceptionOrNull()?.message
"error_message" to response.exceptionOrNull()?.message,
"feed_url" to url
)
)

Expand All @@ -76,9 +77,9 @@ internal class LocalAccountDelegate(
val feed = feedRecords.findBy(id = resultFeed.feedURL.toString())

return if (feed != null) {
verifyFavicon(feed)
upsertFolders(feed, folderTitles)
saveArticles(resultFeed.items, cutoffDate = null, feed = feed)
verifyFavicon(feed)

AddFeedResult.Success(feed)
} else {
Expand Down Expand Up @@ -222,12 +223,14 @@ internal class LocalAccountDelegate(
private fun upsertFolders(feed: Feed, folderTitles: List<String>?) {
folderTitles ?: return

folderTitles.forEach { folderTitle ->
taggingRecords.upsert(
id = "${feed.id}:$folderTitle",
feedID = feed.id,
name = folderTitle
)
database.transactionWithErrorHandling {
folderTitles.forEach { folderTitle ->
taggingRecords.upsert(
id = "${feed.id}:$folderTitle",
feedID = feed.id,
name = folderTitle
)
}
}
}

Expand All @@ -236,15 +239,20 @@ internal class LocalAccountDelegate(
return
}

CapyLog.warn(tag("favicon"), data = mapOf("invalid_favicon_url" to feed.faviconURL))
CapyLog.warn(
tag("favicon"), data = mapOf(
"invalid_favicon_url" to feed.faviconURL,
"feed_url" to feed.feedURL,
)
)

feedRecords.clearFavicon(feed.id)
}

companion object {
private fun tag(path: String) = "$TAG.$path"

private const val TAG = "local_account"
private const val TAG = "local"
}
}

Expand Down
3 changes: 1 addition & 2 deletions capy/src/main/java/com/jocmp/capy/common/OptionalURL.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jocmp.capy.common

import java.net.MalformedURLException
import java.net.URL

fun optionalURL(string: String?): URL? {
Expand All @@ -10,7 +9,7 @@ fun optionalURL(string: String?): URL? {

return try {
URL(string)
} catch (_: MalformedURLException) {
} catch (_: Throwable) {
null
}
}
5 changes: 1 addition & 4 deletions feedfinder/src/main/java/com/jocmp/feedfinder/OptionalURL.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jocmp.feedfinder

import java.net.MalformedURLException
import java.net.URI
import java.net.URL

Expand All @@ -11,9 +10,7 @@ internal fun optionalURL(string: String?): URL? {

return try {
URI(string).toURL()
} catch (_: IllegalArgumentException) {
null
} catch (_: MalformedURLException) {
} catch (_: Throwable) {
null
}
}

0 comments on commit f2b2b38

Please sign in to comment.