refactor(mail): early-return guard in ImapConnectionCache (#357 review)
Restructure isConnectionDrop as leading guard clauses (definite-drop types, then a not-MessagingException early return) instead of a when expression, per maintainer review feedback on PR #368. Behavior is unchanged; verified by the existing ImapConnectionCacheTest suite (all 8 cases still pass), including the FolderClosedException / StoreClosedException cases that depend on the check running before the MessagingException .cause guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -207,10 +207,14 @@ internal class ImapConnectionCache(
|
||||
* while idle, detected on the next op's first command before any mutation is issued — is safe. A
|
||||
* copy-then-expunge move interrupted between its two halves is the rare exception left to that review.
|
||||
*/
|
||||
private fun isConnectionDrop(error: Throwable): Boolean = when (error) {
|
||||
is FolderClosedException, is StoreClosedException, is IOException, is ConnectionException -> true
|
||||
is MessagingException -> error.cause is IOException || error.cause is ConnectionException
|
||||
else -> false
|
||||
private fun isConnectionDrop(error: Throwable): Boolean {
|
||||
// FolderClosedException/StoreClosedException are themselves MessagingException subtypes, so these
|
||||
// definite-drop checks must run before the MessagingException guard below — otherwise they'd fall
|
||||
// into it and get gated on a `.cause` they don't carry, instead of the unconditional `true` below.
|
||||
if (error is FolderClosedException || error is StoreClosedException) return true
|
||||
if (error is IOException || error is ConnectionException) return true
|
||||
if (error !is MessagingException) return false
|
||||
return error.cause is IOException || error.cause is ConnectionException
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
Reference in New Issue
Block a user