securemail: keep authored error messages; assert new permission contract
- Commit
1bcc550696c334bf476fb48afe8ee611cb4de247- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-21 00:56 UTC (15 days ago)
- Parents
8eada76
The friendlyError sweep genericised securemail's authored
domain messages ('Relay offline - kept in outbox.') because
InboxScreen re-mapped every stored error through the mapper.
Authored messages now render verbatim; a toStateError helper
keeps authored error()/IllegalStateException messages from the
view-model and alias controller while genuine exceptions still
go through friendlyError, so raw exception text never surfaces.
communicate's startup test asserted the old first-frame
POST_NOTIFICATIONS request that was deliberately removed; it
now asserts no permission is requested at launch.
Verified: securemail 197, communicate 1970 tests, 0 failures.Diff
communicate/src/test/java/com/vayunmathur/communicate/MainActivitySlice6RoboTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/MainActivitySlice6RoboTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/MainActivitySlice6RoboTest.ktindex 7f129f2299..a42eae34bb 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/MainActivitySlice6RoboTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/MainActivitySlice6RoboTest.kt@@ -1,6 +1,5 @@ package com.vayunmathur.communicate -import android.Manifest import android.content.Intent import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule@@ -15,6 +14,7 @@ import kotlin.test.AfterTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse+import kotlin.test.assertNull import kotlin.test.assertTrue import org.junit.Rule import org.junit.runner.RunWith@@ -31,8 +31,8 @@ import org.robolectric.annotation.Config * hooks (`userLeaving()` dispatches `onUserLeaveHint`, `newIntent(intent)` dispatches * `onNewIntent`) — no production change, no reflection. *- * Covers what only an activity can exercise: the notification-permission gate in- * [MainActivity.onCreateBeforeContent], the picture-in-picture gating in+ * Covers what only an activity can exercise: the no-permission-ask-at-startup+ * contract of [MainActivity.onCreateBeforeContent], the picture-in-picture gating in * [MainActivity.onUserLeaveHint] (driven through the real [InAppCallRegistry] state * machine), and [MainActivity.onNewIntent] deep-link delivery into the nav graph. */@@ -68,11 +68,13 @@ class MainActivitySlice6RoboTest { } @Test- fun launchRequestsNotificationPermission() {- val requested = shadowOf(composeRule.activity).lastRequestedPermission- assertEquals(- listOf(Manifest.permission.POST_NOTIFICATIONS),- requested.requestedPermissions.toList(),+ fun launchDoesNotRequestNotificationPermission() {+ // Deliberate contract (e94deeb00): no POST_NOTIFICATIONS ask on the+ // first frame — no startup permission spam. Robolectric records no+ // permission request at all when launching.+ assertNull(+ shadowOf(composeRule.activity).lastRequestedPermission,+ "launch must not request POST_NOTIFICATIONS (or any permission) at startup", ) }
securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.ktindex e9375613fe..e8c0663e17 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt@@ -199,6 +199,20 @@ class MailViewModel( passphraseCache ?: passphraseLoader()?.also { passphraseCache = it } ?: error("No key passphrase stored — restore from your recovery passphrase.") + /**+ * Maps a failed operation to the text stored in [MailUiState.error].+ *+ * This module raises its own known domain conditions with `error(...)`+ * (relay offline, address taken, disabled sender, key changed, no stored+ * passphrase, ... in this class and [AliasController]): those messages+ * are user-authored and actionable, so keep them verbatim. Every other+ * throwable is a genuine caught exception — never surface its raw text,+ * map it through [friendlyError] instead.+ */+ private fun Throwable.toStateError(): String =+ (this as? IllegalStateException)?.message?.takeIf { it.isNotBlank() }+ ?: getApplication<Application>().friendlyError(this)+ init { config.settings .onEach { s ->@@ -273,7 +287,7 @@ class MailViewModel( }, onFailure = { Log.status(TAG, "claim failed", it)- state.copy(busy = false, error = getApplication<Application>().friendlyError(it))+ state.copy(busy = false, error = it.toStateError()) }, ) }@@ -293,7 +307,7 @@ class MailViewModel( onSuccess = { state.copy(busy = false, message = "Alias $it created.") }, onFailure = { Log.status(TAG, "createAlias failed", it)- state.copy(busy = false, error = getApplication<Application>().friendlyError(it))+ state.copy(busy = false, error = it.toStateError()) }, ) }@@ -574,7 +588,7 @@ class MailViewModel( }, onFailure = { Log.status(TAG, "send failed", it)- state.copy(busy = false, error = getApplication<Application>().friendlyError(it))+ state.copy(busy = false, error = it.toStateError()) .also { onDone(false) } }, )
securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.ktindex d8d6969bf7..46634ee629 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/InboxScreen.kt@@ -37,7 +37,6 @@ import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.ErrorState import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.friendlyErrorMessage import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.rememberMessenger import com.vayunmathur.library.ui.R as UiR@@ -118,9 +117,14 @@ fun InboxScreen( ) { padding -> Column(Modifier.padding(padding).fillMaxSize()) { state.error?.let {+ // state.error is already user-facing: MailViewModel stores+ // authored domain messages verbatim and maps genuine+ // exceptions through friendlyError before storing. Render it+ // as-is — re-mapping here would replace authored text (e.g.+ // "Relay offline — kept in outbox.") with generic wording. ErrorState( title = stringResource(R.string.inbox_something_went_wrong),- message = friendlyErrorMessage(it),+ message = it, retryLabel = stringResource(UiR.string.retry), onRetry = actions.onRetry, )