Protects against crashes when the signer sends an unverifiable payload back to Amethyst

This commit is contained in:
Vitor Pamplona
2026-03-25 08:28:31 -04:00
parent f42881a48e
commit c654d2267c
6 changed files with 51 additions and 1 deletions
@@ -45,6 +45,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.components.toasts.ThrowableToastMsg
import com.vitorpamplona.amethyst.ui.components.toasts.ThrowableToastMsg2
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.Size16dp
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
@@ -72,6 +73,27 @@ fun InformationDialog(
InformationDialog(title = stringRes(obj.titleResId), textContent = str, moreInfo = stack, buttonColors, onDismiss)
}
@Composable
fun InformationDialog(
obj: ThrowableToastMsg2,
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
onDismiss: () -> Unit,
) {
val str = stringRes(obj.description)
val stack =
remember(obj) {
val writer = StringWriter()
writer.append("\n")
obj.throwable.printStackTrace(PrintWriter(writer))
writer.toString()
}
InformationDialog(title = stringRes(obj.titleResId), textContent = str, moreInfo = stack, buttonColors, onDismiss)
}
@Composable
fun InformationDialog(
title: String,
@@ -82,6 +82,12 @@ fun DisplayErrorMessages(
}
}
is ThrowableToastMsg2 -> {
InformationDialog(obj) {
toastManager.clearToasts()
}
}
is MultiErrorToastMsg -> {
MultiUserErrorMessageDialog(obj, accountViewModel, nav)
}
@@ -28,3 +28,10 @@ class ThrowableToastMsg(
val msg: String? = null,
val throwable: Throwable,
) : ToastMsg()
@Immutable
class ThrowableToastMsg2(
val titleResId: Int,
val description: Int,
val throwable: Throwable,
) : ToastMsg()
@@ -62,6 +62,14 @@ class ToastManager {
toasts.tryEmit(ThrowableToastMsg(titleResId, message, throwable))
}
fun toast(
titleResId: Int,
description: Int,
throwable: Throwable,
) {
toasts.tryEmit(ThrowableToastMsg2(titleResId, description, throwable))
}
fun toast(
titleResId: Int,
resourceId: Int,
@@ -962,6 +962,12 @@ class AccountViewModel(
Log.w("AccountViewModel", "AutomaticallyUnauthorizedException", e)
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
Log.w("AccountViewModel", "TimedOutRunningOnBackgroundWithoutAutomaticPermissionExceptionException", e)
} catch (e: IllegalStateException) {
toastManager.toast(
R.string.signer_not_found_exception,
R.string.signer_illegal_state_exception_description,
e,
)
}
}
}
+2 -1
View File
@@ -68,7 +68,8 @@
<string name="signer_not_found_exception">Signer not found</string>
<string name="signer_not_found_exception_description">Was the Signer app uninstalled? Check if the signer is installed and has this account. Log off and Log in again of the signer app has changed.</string>
<string name="signer_illegal_state_exception">Signer misbehaved</string>
<string name="signer_illegal_state_exception_description">External signer returned a payload that is strange for the request. There might be a bug on either Amethyst or the Signer.</string>
<string name="zaps">Zaps</string>
<string name="view_count">View count</string>