Skip to content

Commit 32a9101

Browse files
jvsena42claude
andcommitted
fix: distinguish probe failure from false in keychain diagnostic
Probes for aliasPresent, entryPresent and walletIndex previously collapsed any exception inside runCatching to the default value, making a keystore subsystem / DataStore / Room error indistinguishable from a legitimate 'alias missing'. Render tri-state instead: 'true' / 'false' / 'error:ClassName'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7b87d7b commit 32a9101

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

app/src/main/java/to/bitkit/data/keychain/Keychain.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ class Keychain @Inject constructor(
143143
private fun emitLoadDiagnosticsOnce(key: String, cause: Throwable) {
144144
if (!loadDiagnosticsEmitted.add(key)) return
145145

146-
val aliasPresent = runCatching { keyStore.containsAlias() }.getOrDefault(false)
147-
val entryPresent = runCatching { snapshot.contains(key.indexed) }.getOrDefault(false)
148-
val walletIndex = runCatching {
146+
val aliasPresent = probe { keyStore.containsAlias() }
147+
val entryPresent = probe { snapshot.contains(key.indexed) }
148+
val walletIndex = probe {
149149
runBlocking { db.configDao().getAll().first() }.firstOrNull()?.walletIndex ?: 0L
150-
}.getOrDefault(-1L)
150+
}
151151
val causeChain = generateSequence(cause) { it.cause }
152152
.take(CAUSE_CHAIN_DEPTH)
153153
.joinToString(separator = " <- ") { it.javaClass.simpleName }
@@ -160,6 +160,12 @@ class Keychain @Inject constructor(
160160
)
161161
}
162162

163+
private inline fun <T> probe(block: () -> T): String =
164+
runCatching(block).fold(
165+
onSuccess = { it.toString() },
166+
onFailure = { "error:${it.javaClass.simpleName}" },
167+
)
168+
163169
enum class Key {
164170
PUSH_NOTIFICATION_TOKEN,
165171
PUSH_NOTIFICATION_PRIVATE_KEY,

0 commit comments

Comments
 (0)