diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 6a0d42777d..3cb1887381 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -44,6 +44,7 @@ import org.session.libsession.messaging.messages.signal.IncomingGroupMessage import org.session.libsession.messaging.messages.signal.IncomingTextMessage import org.session.libsession.messaging.messages.signal.OutgoingTextMessage import org.session.libsession.utilities.preferences.ProfileKeyUtil +import org.session.libsignal.service.loki.utilities.prettifiedDescription class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), StorageProtocol { override fun getUserPublicKey(): String? { @@ -368,6 +369,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val smsDatabase = DatabaseFactory.getSmsDatabase(context) smsDatabase.markAsSentFailed(messageRecord.getId()) } + if (error.localizedMessage != null) { + DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.localizedMessage!!) + } else { + DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.javaClass.simpleName) + } } override fun getGroup(groupID: String): GroupRecord? { diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt index 37eafe8b1b..f46a124ca8 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt @@ -17,7 +17,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long) private val MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object NoAttachment : Error("No such attachment.") } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt index 847d4a3b88..94b7a9d26a 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt @@ -25,7 +25,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess override var failureCount: Int = 0 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object NoAttachment : Error("No such attachment.") } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt index 5b661327cb..8412ddcc61 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt @@ -11,7 +11,7 @@ object MessageReceiver { private val lastEncryptionKeyPairRequest = mutableMapOf() - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object DuplicateMessage: Error("Duplicate message.") object InvalidMessage: Error("Invalid message.") object UnknownMessage: Error("Unknown message type.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 39a0237000..ebab94b9aa 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -34,7 +34,7 @@ import org.session.libsignal.utilities.logging.Log object MessageSender { // Error - sealed class Error(val description: String) : Exception() { + sealed class Error(val description: String) : Exception(description) { object InvalidMessage : Error("Invalid message.") object ProtoConversionFailed : Error("Couldn't convert message to proto.") object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.") @@ -202,6 +202,11 @@ object MessageSender { val preconditionFailure = Exception("Destination should not be contacts or closed groups!") message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } message.sender = storage.getUserPublicKey() + // Set the failure handler (need it here already for precondition failure handling) + fun handleFailure(error: Exception) { + handleFailedMessageSend(message, error) + deferred.reject(error) + } try { val server: String val channel: Long @@ -214,19 +219,12 @@ object MessageSender { channel = destination.channel } } - // Set the failure handler (need it here already for precondition failure handling) - fun handleFailure(error: Exception) { - handleFailedMessageSend(message, error) - deferred.reject(error) - } // Validate the message if (message !is VisibleMessage || !message.isValid()) { - handleFailure(Error.InvalidMessage) throw Error.InvalidMessage } // Convert the message to an open group message val openGroupMessage = OpenGroupMessage.from(message, server) ?: kotlin.run { - handleFailure(Error.InvalidMessage) throw Error.InvalidMessage } // Send the result @@ -238,7 +236,7 @@ object MessageSender { handleFailure(it) } } catch (exception: Exception) { - deferred.reject(exception) + handleFailure(exception) } return deferred.promise } diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt index 49853b33e2..0856e43862 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt @@ -42,7 +42,7 @@ open class DotNetAPI { internal enum class HTTPVerb { GET, PUT, POST, DELETE, PATCH } // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") object InvalidURL : Error("Invalid URL.") object ParsingFailed : Error("Invalid file server response.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt index 9305852258..b11cbe1774 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/MessageWrapper.kt @@ -10,7 +10,7 @@ import java.security.SecureRandom object MessageWrapper { // region Types - sealed class Error(val description: String) : Exception() { + sealed class Error(val description: String) : Exception(description) { object FailedToWrapData : Error("Failed to wrap data.") object FailedToWrapMessageInEnvelope : Error("Failed to wrap message in envelope.") object FailedToWrapEnvelopeInWebSocketMessage : Error("Failed to wrap envelope in web socket message.") diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 1b17a02211..98b711af60 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -45,7 +45,7 @@ object SnodeAPI { internal var powDifficulty = 1 // Error - internal sealed class Error(val description: String) : Exception() { + internal sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") object ClockOutOfSync : Error("The user's clock is out of sync with the service node network.") object RandomSnodePoolUpdatingFailed : Error("Failed to update random service node pool.") diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt index 192218d399..b3c15dd132 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt @@ -50,7 +50,7 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { } } - sealed class DecodingError(val description: String) : Exception() { + sealed class DecodingError(val description: String) : Exception(description) { object Generic : DecodingError("Something went wrong. Please check your mnemonic and try again.") object InputTooShort : DecodingError("Looks like you didn't enter enough words. Please check your mnemonic and try again.") object MissingLastWord : DecodingError("You seem to be missing the last word of your mnemonic. Please check what you entered and try again.")