Skip to content

Commit

Permalink
Log all exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Jan 30, 2024
1 parent a2038b6 commit 2864d5c
Show file tree
Hide file tree
Showing 50 changed files with 158 additions and 76 deletions.
17 changes: 1 addition & 16 deletions app/detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>CyclomaticComplexMethod:ChatScreen.kt$@Composable private fun ChatMessageListItem( chatMessage: ChatMessageUi, previousMessage: ChatMessageUi? = null, nextMessage: ChatMessageUi? = null, onProfileClick: (String) -&gt; Unit, onNoteClick: (String) -&gt; Unit, onUrlClick: (String) -&gt; Unit, onHashtagClick: (String) -&gt; Unit, onMediaClick: (String, String) -&gt; Unit, )</ID>
<ID>CyclomaticComplexMethod:CreateAccountViewModel.kt$CreateAccountViewModel$private fun observeEvents()</ID>
Expand Down Expand Up @@ -39,7 +40,6 @@
<ID>LongMethod:ExploreFeedScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun ExploreFeedScreen( state: ExploreFeedContract.UiState, onClose: () -&gt; Unit, onPostClick: (String) -&gt; Unit, onPostReplyClick: (String) -&gt; Unit, onPostQuoteClick: (String) -&gt; Unit, onProfileClick: (String) -&gt; Unit, onHashtagClick: (String) -&gt; Unit, onMediaClick: (String, String) -&gt; Unit, onGoToWallet: () -&gt; Unit, eventPublisher: (ExploreFeedContract.UiEvent) -&gt; Unit, )</ID>
<ID>LongMethod:ExploreHomeScreen.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable fun ExploreHomeScreen( state: ExploreHomeContract.UiState, onHashtagClick: (String) -&gt; Unit, onSearchClick: () -&gt; Unit, onPrimaryDestinationChanged: (PrimalTopLevelDestination) -&gt; Unit, onDrawerDestinationClick: (DrawerScreenDestination) -&gt; Unit, eventPublisher: (UiEvent) -&gt; Unit, )</ID>
<ID>LongMethod:FeedLazyColumn.kt$@ExperimentalMaterial3Api @ExperimentalFoundationApi @Composable fun FeedLazyColumn( pagingItems: LazyPagingItems&lt;FeedPostUi&gt;, contentPadding: PaddingValues, listState: LazyListState, zappingState: ZappingState, onPostClick: (String) -&gt; Unit, onProfileClick: (String) -&gt; Unit, onPostLikeClick: (FeedPostUi) -&gt; Unit, onRepostClick: (FeedPostUi) -&gt; Unit, onZapClick: (FeedPostUi, ULong?, String?) -&gt; Unit, onPostReplyClick: (String) -&gt; Unit, onPostQuoteClick: (FeedPostUi) -&gt; Unit, onHashtagClick: (String) -&gt; Unit, onMediaClick: (String, String) -&gt; Unit, onGoToWallet: () -&gt; Unit, onMuteClick: ((String) -&gt; Unit)? = null, shouldShowLoadingState: Boolean = true, shouldShowNoContentState: Boolean = true, header: @Composable (LazyItemScope.() -&gt; Unit)? = null, stickyHeader: @Composable (LazyItemScope.() -&gt; Unit)? = null, )</ID>
<ID>LongMethod:FeedNoteCard.kt$@Composable fun FeedNoteCard( data: FeedPostUi, modifier: Modifier = Modifier, shape: Shape = CardDefaults.shape, colors: CardColors = CardDefaults.cardColors(), cardPadding: PaddingValues = PaddingValues(all = 0.dp), fullWidthNote: Boolean = false, headerSingleLine: Boolean = true, fullWidthContent: Boolean = false, forceContentIndent: Boolean = false, drawLineAboveAvatar: Boolean = false, drawLineBelowAvatar: Boolean = false, expanded: Boolean = false, onPostClick: (String) -&gt; Unit, onProfileClick: (String) -&gt; Unit, onPostAction: ((FeedPostAction) -&gt; Unit)? = null, onPostLongClickAction: ((FeedPostAction) -&gt; Unit)? = null, onHashtagClick: (String) -&gt; Unit, onMediaClick: (String, String) -&gt; Unit, onMuteUserClick: () -&gt; Unit, )</ID>
<ID>LongMethod:FeedRemoteMediator.kt$FeedRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState&lt;Int, FeedPost&gt;): MediatorResult</ID>
<ID>LongMethod:FeedScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun FeedScreen( state: FeedContract.UiState, eventPublisher: (FeedContract.UiEvent) -&gt; Unit, onFeedsClick: () -&gt; Unit, onNewPostClick: (String?) -&gt; Unit, onPostClick: (String) -&gt; Unit, onPostReplyClick: (String) -&gt; Unit, onProfileClick: (String) -&gt; Unit, onHashtagClick: (String) -&gt; Unit, onMediaClick: (String, String) -&gt; Unit, onGoToWallet: () -&gt; Unit, onPrimaryDestinationChanged: (PrimalTopLevelDestination) -&gt; Unit, onDrawerDestinationClick: (DrawerScreenDestination) -&gt; Unit, )</ID>
<ID>LongMethod:FeedsSettingsScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun FeedsSettingsScreen( state: FeedsSettingsContract.UiState, eventPublisher: (FeedsSettingsContract.UiEvent) -&gt; Unit, onClose: () -&gt; Unit, )</ID>
Expand Down Expand Up @@ -151,21 +151,6 @@
<ID>ReturnCount:NotificationEvents.kt$fun ContentPrimalNotification.asNotificationPOOrNull(): NotificationData?</ID>
<ID>ReturnCount:NotificationsRemoteMediator.kt$NotificationsRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState&lt;Int, Notification&gt;): MediatorResult</ID>
<ID>ReturnCount:WalletTransactionsMediator.kt$WalletTransactionsMediator$override suspend fun load(loadType: LoadType, state: PagingState&lt;Int, WalletTransaction&gt;): MediatorResult</ID>
<ID>SwallowedException:CredentialsStore.kt$CredentialsStore$error: DecoderException</ID>
<ID>SwallowedException:CredentialsStore.kt$CredentialsStore$error: IllegalArgumentException</ID>
<ID>SwallowedException:EditProfileViewModel.kt$EditProfileViewModel$error: WssException</ID>
<ID>SwallowedException:NostrEvents.kt$error: IllegalArgumentException</ID>
<ID>SwallowedException:NostrNotary.kt$NostrNotary$error: IllegalArgumentException</ID>
<ID>SwallowedException:Parsers.kt$error: SerializationException</ID>
<ID>SwallowedException:PostRepository.kt$PostRepository$error: WssException</ID>
<ID>SwallowedException:PrimalProfileStatsAndScores.kt$error: IllegalArgumentException</ID>
<ID>SwallowedException:ProfileScreen.kt$error: ActivityNotFoundException</ID>
<ID>SwallowedException:RelayPool.kt$RelayPool$error: IllegalArgumentException</ID>
<ID>SwallowedException:SearchViewModel.kt$SearchViewModel$error: WssException</ID>
<ID>SwallowedException:UriHandlerExt.kt$error: ActivityNotFoundException</ID>
<ID>SwallowedException:ValidationUtils.kt$error: DecoderException</ID>
<ID>SwallowedException:ValidationUtils.kt$error: IllegalArgumentException</ID>
<ID>SwallowedException:WalletActivationScreen.kt$error: IOException</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:ExploreFeedViewModel.kt$ExploreFeedViewModel$IllegalStateException()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:FeedViewModel.kt$FeedViewModel$IllegalStateException()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:NotificationsViewModel.kt$NotificationsViewModel$IllegalStateException()</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PlayBillingClient @Inject constructor(
}
}
} catch (error: TimeoutCancellationException) {
Timber.e(error)
Timber.w(error)
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ class CreateAccountViewModel @Inject constructor(
currentStep = UiState.CreateAccountStep.ACCOUNT_CREATED,
)
}
} catch (e: UnsuccessfulFileUpload) {
setState { copy(error = UiState.CreateError.FailedToUploadImage(e)) }
} catch (e: NostrPublishException) {
setState { copy(error = UiState.CreateError.FailedToCreateMetadata(e)) }
} catch (e: WssException) {
setState { copy(error = UiState.CreateError.FailedToCreateMetadata(e)) }
} catch (error: UnsuccessfulFileUpload) {
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToUploadImage(error)) }
} catch (error: NostrPublishException) {
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToCreateMetadata(error)) }
} catch (error: WssException) {
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToCreateMetadata(error)) }
} finally {
setState { copy(loading = false) }
}
Expand Down Expand Up @@ -158,8 +161,9 @@ class CreateAccountViewModel @Inject constructor(
currentStep = UiState.CreateAccountStep.FOLLOW_RECOMMENDED_ACCOUNTS,
)
}
} catch (e: IOException) {
setState { copy(error = UiState.CreateError.FailedToFetchRecommendedFollows(e)) }
} catch (error: IOException) {
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToFetchRecommendedFollows(error)) }
} finally {
setState { copy(loading = false) }
}
Expand All @@ -181,10 +185,10 @@ class CreateAccountViewModel @Inject constructor(
}
setEffect(SideEffect.AccountCreatedAndPersisted(pubkey = userId))
} catch (error: NostrPublishException) {
Timber.e(error)
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToFollow(error)) }
} catch (error: WssException) {
Timber.e(error)
Timber.w(error)
setState { copy(error = UiState.CreateError.FailedToFollow(error)) }
} finally {
setState { copy(loading = false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class LoginViewModel @Inject constructor(
val defaultFeed = withContext(dispatcherProvider.io()) { feedRepository.defaultFeed() }
setEffect(SideEffect.LoginSuccess(feedDirective = defaultFeed?.directive ?: userId))
} catch (error: WssException) {
Timber.e(error)
Timber.w(error)
setErrorState(error = UiState.LoginError.GenericError(error))
} finally {
setState { copy(loading = false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package net.primal.android.core.ext

import android.content.ActivityNotFoundException
import androidx.compose.ui.platform.UriHandler
import timber.log.Timber

fun UriHandler.openUriSafely(uri: String) {
try {
openUri(uri)
} catch (error: ActivityNotFoundException) {
Timber.w(error)
runCatching {
val scheme = if (uri.contains("@")) "mailto" else "https"
openUri("$scheme://$uri")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import net.primal.android.networking.primal.PrimalVerb
import net.primal.android.networking.sockets.errors.WssException
import net.primal.android.nostr.model.NostrEventKind
import net.primal.android.nostr.notary.NostrNotary
import timber.log.Timber

@Singleton
class FileUploader @Inject constructor(
Expand Down Expand Up @@ -48,10 +49,13 @@ class FileUploader @Inject constructor(
),
)
} catch (error: WssException) {
Timber.w(error)
throw UnsuccessfulFileUpload(cause = error)
} catch (error: IOException) {
Timber.w(error)
throw UnsuccessfulFileUpload(cause = error)
} catch (error: UnknownHostException) {
Timber.w(error)
throw UnsuccessfulFileUpload(cause = error)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline fun <reified T> Json.decodeFromStringOrNull(string: String?): T? {
return try {
decodeFromString(string)
} catch (error: IllegalArgumentException) {
Timber.e(error)
Timber.w(error)
null
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/net/primal/android/core/utils/UriUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.linkedin.urls.detection.UrlDetectorOptions
import java.net.MalformedURLException
import java.net.URL
import net.primal.android.nostr.ext.parseNostrUris
import timber.log.Timber

fun String.parseUris(): List<String> {
val urlDetector = UrlDetector(this, UrlDetectorOptions.JSON)
Expand Down Expand Up @@ -82,6 +83,7 @@ fun String?.detectMimeType(): String? {
val ref = try {
URL(this).file
} catch (error: MalformedURLException) {
Timber.w(error)
this
}
val extension = ref.substringAfterLast(".", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.primal.android.crypto.Bech32
import net.primal.android.crypto.hexToNpubHrp
import net.primal.android.crypto.hexToNsecHrp
import org.spongycastle.util.encoders.DecoderException
import timber.log.Timber

fun String?.isValidNostrPrivateKey(): Boolean {
if (this == null) return false
Expand All @@ -14,6 +15,7 @@ fun String?.isValidNostrPrivateKey(): Boolean {
try {
this.hexToNsecHrp().isValidNsec()
} catch (error: DecoderException) {
Timber.w(error)
false
}
}
Expand All @@ -28,6 +30,7 @@ fun String?.isValidNostrPublicKey(): Boolean {
try {
this.hexToNpubHrp().isValidNpub()
} catch (error: DecoderException) {
Timber.w(error)
false
}
}
Expand All @@ -40,6 +43,7 @@ private fun String.isValidNsec(): Boolean {
val decoded = Bech32.decodeBytes(this)
decoded.first == "nsec" && decoded.second.size == 32
} catch (error: IllegalArgumentException) {
Timber.w(error)
false
}
}
Expand All @@ -53,6 +57,7 @@ private fun String.isValidNpub(): Boolean {
val decoded = Bech32.decodeBytes(this)
decoded.first == "npub" && this.length >= NPUB_LENGTH
} catch (error: IllegalArgumentException) {
Timber.w(error)
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import net.primal.android.wallet.zaps.InvalidZapRequestException
import net.primal.android.wallet.zaps.ZapFailureException
import net.primal.android.wallet.zaps.ZapHandler
import net.primal.android.wallet.zaps.hasWallet
import timber.log.Timber

@HiltViewModel
class FeedViewModel @Inject constructor(
Expand Down Expand Up @@ -197,8 +198,10 @@ class FeedViewModel @Inject constructor(
postAuthorId = postLikeAction.postAuthorId,
)
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = FeedError.FailedToPublishLikeEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = FeedError.MissingRelaysConfiguration(error))
}
}
Expand All @@ -212,8 +215,10 @@ class FeedViewModel @Inject constructor(
postRawNostrEvent = repostAction.postNostrEvent,
)
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = FeedError.FailedToPublishRepostEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = FeedError.MissingRelaysConfiguration(error))
}
}
Expand Down Expand Up @@ -241,10 +246,13 @@ class FeedViewModel @Inject constructor(
),
)
} catch (error: ZapFailureException) {
Timber.w(error)
setErrorState(error = FeedError.FailedToPublishZapEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = FeedError.MissingRelaysConfiguration(error))
} catch (error: InvalidZapRequestException) {
Timber.w(error)
setErrorState(error = FeedError.InvalidZapRequest(error))
}
}
Expand All @@ -257,8 +265,10 @@ class FeedViewModel @Inject constructor(
mutedUserId = action.userId,
)
} catch (error: WssException) {
Timber.w(error)
setErrorState(error = FeedError.FailedToMuteUser(error))
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = FeedError.FailedToMuteUser(error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FeedListViewModel @Inject constructor(
settingsRepository.fetchAndPersistAppSettings(userId = activeAccountStore.activeUserId())
}
} catch (error: WssException) {
Timber.e(error)
Timber.w(error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class NoteEditorViewModel @Inject constructor(
feedRepository.fetchReplies(postId = replyToNoteId)
}
} catch (error: WssException) {
Timber.e(error)
Timber.w(error)
}
}

Expand All @@ -146,11 +146,11 @@ class NoteEditorViewModel @Inject constructor(
)
sendEffect(SideEffect.PostPublished)
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = UiState.NewPostError.PublishError(cause = error.cause))
} catch (error: MissingRelaysException) {
setErrorState(
error = UiState.NewPostError.MissingRelaysConfiguration(cause = error),
)
Timber.w(error)
setErrorState(error = UiState.NewPostError.MissingRelaysConfiguration(cause = error))
} finally {
setState { copy(publishing = false) }
}
Expand Down Expand Up @@ -189,6 +189,7 @@ class NoteEditorViewModel @Inject constructor(
)
}
} catch (error: UnsuccessfulFileUpload) {
Timber.w(error)
updateNoteAttachmentState(attachment = attachment.copy(uploadError = error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import net.primal.android.wallet.zaps.InvalidZapRequestException
import net.primal.android.wallet.zaps.ZapFailureException
import net.primal.android.wallet.zaps.ZapHandler
import net.primal.android.wallet.zaps.hasWallet
import timber.log.Timber

@HiltViewModel
class ExploreFeedViewModel @Inject constructor(
Expand Down Expand Up @@ -128,6 +129,7 @@ class ExploreFeedViewModel @Inject constructor(
directive = exploreQuery,
)
} catch (error: WssException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToAddToFeed(error))
}
}
Expand All @@ -139,6 +141,7 @@ class ExploreFeedViewModel @Inject constructor(
directive = exploreQuery,
)
} catch (error: WssException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToRemoveFeed(error))
}
}
Expand All @@ -151,8 +154,10 @@ class ExploreFeedViewModel @Inject constructor(
postAuthorId = postLikeAction.postAuthorId,
)
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToPublishLikeEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.MissingRelaysConfiguration(error))
}
}
Expand All @@ -166,8 +171,10 @@ class ExploreFeedViewModel @Inject constructor(
postRawNostrEvent = repostAction.postNostrEvent,
)
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToPublishRepostEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.MissingRelaysConfiguration(error))
}
}
Expand Down Expand Up @@ -197,10 +204,13 @@ class ExploreFeedViewModel @Inject constructor(
),
)
} catch (error: ZapFailureException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToPublishZapEvent(error))
} catch (error: MissingRelaysException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.MissingRelaysConfiguration(error))
} catch (error: InvalidZapRequestException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.InvalidZapRequest(error))
}
}
Expand All @@ -213,8 +223,10 @@ class ExploreFeedViewModel @Inject constructor(
mutedUserId = action.profileId,
)
} catch (error: WssException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToMuteUser(error))
} catch (error: NostrPublishException) {
Timber.w(error)
setErrorState(error = ExploreFeedError.FailedToMuteUser(error))
}
}
Expand Down
Loading

0 comments on commit 2864d5c

Please sign in to comment.