Merge pull request #7627 from thunderbird/more_error_logging

Add more debug logging when checking server settings
This commit is contained in:
cketti 2024-02-13 14:21:11 +01:00 committed by GitHub
commit b893883d13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 14 deletions

View file

@ -212,15 +212,17 @@ internal open class RealImapStore(
return folderName.substring(prefixLength)
}
@Throws(MessagingException::class)
@Suppress("TooGenericExceptionCaught")
@Throws(MessagingException::class, IOException::class)
override fun checkSettings() {
try {
val connection = createImapConnection()
connection.open()
connection.close()
} catch (e: IOException) {
throw MessagingException("Unable to connect", e)
} catch (e: Exception) {
Timber.e(e, "Error while checking server settings")
throw e
}
}

View file

@ -1,11 +1,8 @@
package com.fsck.k9.mail.store.imap
import assertk.all
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.cause
import assertk.assertions.containsExactly
import assertk.assertions.hasMessage
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import assertk.assertions.isSameInstanceAs
@ -44,18 +41,16 @@ class RealImapStoreTest {
}
@Test
fun `checkSettings() with open throwing should throw MessagingException`() {
fun `checkSettings() with open throwing an IOException should pass it through`() {
val ioException = IOException()
val imapConnection = createMockConnection().stub {
on { open() } doThrow IOException::class
on { open() } doThrow ioException
}
imapStore.enqueueImapConnection(imapConnection)
assertFailure {
imapStore.checkSettings()
}.isInstanceOf<MessagingException>().all {
hasMessage("Unable to connect")
cause().isNotNull().isInstanceOf<IOException>()
}
}.isSameInstanceAs(ioException)
}
@Test

View file

@ -4,6 +4,7 @@ package com.fsck.k9.mail.store.pop3;
import java.util.HashMap;
import java.util.Map;
import com.fsck.k9.logging.Timber;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.MessagingException;
@ -54,8 +55,10 @@ public class Pop3Store {
try {
folder.open();
folder.requestUidl();
}
finally {
} catch (Exception e) {
Timber.e(e, "Error while checking server settings");
throw e;
} finally {
folder.close();
}
}

View file

@ -665,12 +665,16 @@ class SmtpTransport(
}
}
@Suppress("TooGenericExceptionCaught")
@Throws(MessagingException::class)
fun checkSettings() {
ensureClosed()
try {
open()
} catch (e: Exception) {
Timber.e(e, "Error while checking server settings")
throw e
} finally {
close()
}