diff --git a/ProtonMail/ProtonMail/Services/APP_share/MessageDataService/MessageDataService.swift b/ProtonMail/ProtonMail/Services/APP_share/MessageDataService/MessageDataService.swift index a16fb0626..de5df6968 100644 --- a/ProtonMail/ProtonMail/Services/APP_share/MessageDataService/MessageDataService.swift +++ b/ProtonMail/ProtonMail/Services/APP_share/MessageDataService/MessageDataService.swift @@ -907,7 +907,7 @@ class MessageDataService: MessageDataServiceProtocol, LocalMessageDataServicePro ] let messages = try fetchRequest.execute() guard let first = messages.first else { - throw NSError(domain: "proton.ch", code: APIErrorCode.resourceDoesNotExist) + throw MessageDataServiceError.messageNotFoundForMessageID(messageID) } return first } @@ -1261,3 +1261,14 @@ extension MessageDataService { let viewModeDataSource: ViewModeDataSource } } + +enum MessageDataServiceError: LocalizedError { + case messageNotFoundForMessageID(MessageID) + + var errorDescription: String? { + switch self { + case .messageNotFoundForMessageID(let messageID): + return "Message not found for MessageID \(messageID.rawValue)" + } + } +} diff --git a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/MessageActionUpdateUseCase.swift b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/MessageActionUpdateUseCase.swift index 1e6363bf9..af653f9d4 100644 --- a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/MessageActionUpdateUseCase.swift +++ b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/MessageActionUpdateUseCase.swift @@ -57,7 +57,7 @@ final class MessageActionUpdate: MessageActionUpdateUseCase { } if rawMessageIDs.isEmpty { if !ProcessInfo.isRunningUnitTests { - PMAssertionFailure("Raw messageIDs is empty") + PMAssertionFailure("Raw messageIDs is empty, executing action: \(action)") } return } diff --git a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadAttachmentUseCase.swift b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadAttachmentUseCase.swift index ec3551164..7ce81ebda 100644 --- a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadAttachmentUseCase.swift +++ b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadAttachmentUseCase.swift @@ -34,8 +34,9 @@ final class UploadAttachment: UploadAttachmentUseCase { func execute(attachmentURI: String) async throws { guard let attachment = try dependencies.messageDataService.getAttachmentEntity(for: attachmentURI) else { - postNotification(error: UploadAttachmentError.resourceDoesNotExist, attachmentURI: attachmentURI) - throw UploadAttachmentError.resourceDoesNotExist + let error = UploadAttachmentError.attachmentDoesNotExist(attachmentURI) + postNotification(error: error, attachmentURI: attachmentURI) + throw error } let messageEntity = try dependencies.messageDataService.getMessageEntity(for: attachment.messageID) @@ -94,7 +95,7 @@ final class UploadAttachment: UploadAttachmentUseCase { ] let messageURI = message.objectID.rawValue.uriRepresentation().absoluteString guard let sendingData = dependencies.messageDataService.getMessageSendingData(for: messageURI) else { - throw UploadAttachmentError.resourceDoesNotExist + throw UploadAttachmentError.messageDoesNotExist(messageURI) } guard let addressID = sendingData.cachedSenderAddress?.addressID ?? @@ -203,15 +204,18 @@ extension UploadAttachment { typealias UploadingResponse = (response: JSONDictionary, keyPacket: Data) - enum UploadAttachmentError: LocalizedError { - case resourceDoesNotExist + enum UploadAttachmentError: LocalizedError, Equatable { + case attachmentDoesNotExist(String) + case messageDoesNotExist(String) case duplicatedUploading case encryptionError var errorDescription: String? { switch self { - case .resourceDoesNotExist: - return "resource doesn't exist" + case .attachmentDoesNotExist(let uri): + return "attachment doesn't exist (\(uri))" + case .messageDoesNotExist(let uri): + return "message doesn't exist (\(uri))" case .duplicatedUploading: return "duplicated uploading" case .encryptionError: diff --git a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadDraftUseCase.swift b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadDraftUseCase.swift index cc887487d..55a058e16 100644 --- a/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadDraftUseCase.swift +++ b/ProtonMail/ProtonMail/Utilities/APP_share/UseCase/UploadDraftUseCase.swift @@ -36,7 +36,7 @@ final class UploadDraft: UploadDraftUseCase { func execute(messageObjectID: String) async throws { do { guard let messageData = dependencies.messageDataService.getMessageSendingData(for: messageObjectID) else { - throw UploadDraftError.resourceDoesNotExist + throw UploadDraftError.messageNotFoundForURI(messageObjectID) } let jsonResponse = try await sendUploadRequest(messageData: messageData) try apply(response: jsonResponse, to: messageObjectID) @@ -62,7 +62,7 @@ final class UploadDraft: UploadDraftUseCase { if error.localizedDescription.isEmpty { let code = error.bestShotAtReasonableErrorCode PMAssertionFailure("Attempting to display error with empty description, code \(code)") - }else { + } else { SystemLogger.log(error: error, category: .emptyAlert) } await NSError.alertSavingDraftError(details: error.localizedDescription) @@ -174,7 +174,14 @@ extension UploadDraft { } } - enum UploadDraftError: Error, Equatable { - case resourceDoesNotExist + enum UploadDraftError: LocalizedError, Equatable { + case messageNotFoundForURI(String) + + var errorDescription: String? { + switch self { + case .messageNotFoundForURI(let uri): + return "Message not found for URI: \(uri)" + } + } } } diff --git a/ProtonMail/ProtonMailTests/Mocks/Services/MessageDataService/MockMessageDataService.swift b/ProtonMail/ProtonMailTests/Mocks/Services/MessageDataService/MockMessageDataService.swift index 855ad3b55..827039ff3 100644 --- a/ProtonMail/ProtonMailTests/Mocks/Services/MessageDataService/MockMessageDataService.swift +++ b/ProtonMail/ProtonMailTests/Mocks/Services/MessageDataService/MockMessageDataService.swift @@ -160,11 +160,6 @@ class MockMessageDataService: MessageDataServiceProtocol { return defaultUserAddressStub(addressID) } - @ThrowingFuncStub(MockMessageDataService.getMessage, initialReturn: Message()) var getMessageStub - func getMessage(for messageID: ProtonMail.MessageID) throws -> ProtonMail.Message { - try getMessageStub(messageID) - } - @ThrowingFuncStub(MockMessageDataService.getMessageEntity, initialReturn: MessageEntity(Message())) var getMessageEntityStub func getMessageEntity(for messageID: ProtonMail.MessageID) throws -> ProtonMail.MessageEntity { try getMessageEntityStub(messageID) @@ -184,9 +179,4 @@ class MockMessageDataService: MessageDataServiceProtocol { func updateAttachment(by uploadResponse: ProtonMail.UploadAttachment.UploadingResponse, attachmentObjectID: ProtonMail.ObjectID) { updateAttachmentStub(uploadResponse, attachmentObjectID) } - - @FuncStub(MockMessageDataService.removeAllAttachmentsNotUploaded) var removeAllAttachmentsNotUploadedStub - func removeAllAttachmentsNotUploaded(messageID: ProtonMail.MessageID) { - removeAllAttachmentsNotUploadedStub(messageID) - } } diff --git a/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadAttachmentUseCaseTest.swift b/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadAttachmentUseCaseTest.swift index d8d1f4d60..5b48eb837 100644 --- a/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadAttachmentUseCaseTest.swift +++ b/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadAttachmentUseCaseTest.swift @@ -52,7 +52,7 @@ final class UploadAttachmentUseCaseTest: XCTestCase { XCTFail("Shouldn't success") } catch { let uploadError = try XCTUnwrap(error as? UploadAttachment.UploadAttachmentError) - XCTAssertEqual(uploadError, .resourceDoesNotExist) + XCTAssertEqual(uploadError, .attachmentDoesNotExist("123")) } } diff --git a/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadDraftUseCaseTest.swift b/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadDraftUseCaseTest.swift index 8d2f14d88..e7278cbae 100644 --- a/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadDraftUseCaseTest.swift +++ b/ProtonMail/ProtonMailTests/ProtonMail/Utilities/UseCases/UploadDraftUseCaseTest.swift @@ -63,7 +63,7 @@ final class UploadDraftUseCaseTest: XCTestCase { XCTFail("Should throw error") } catch { let receivedError = try XCTUnwrap(error as? UploadDraft.UploadDraftError) - XCTAssertEqual(receivedError, .resourceDoesNotExist) + XCTAssertEqual(receivedError, .messageNotFoundForURI(fakeID)) } }