From 36ba02e18cddb76429df193943ecb2a72a88e508 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Wed, 14 Apr 2021 09:59:12 -0400 Subject: [PATCH 1/2] Update ParseError codes --- .../API/URLSession+extensions.swift | 4 +- Sources/ParseSwift/Types/ParseError.swift | 131 +++++++++++++----- Tests/ParseSwiftTests/APICommandTests.swift | 2 +- Tests/ParseSwiftTests/ParseCloudTests.swift | 8 +- 4 files changed, 107 insertions(+), 38 deletions(-) diff --git a/Sources/ParseSwift/API/URLSession+extensions.swift b/Sources/ParseSwift/API/URLSession+extensions.swift index f78366ad3..ade4ad920 100755 --- a/Sources/ParseSwift/API/URLSession+extensions.swift +++ b/Sources/ParseSwift/API/URLSession+extensions.swift @@ -29,7 +29,7 @@ extension URLSession { mapper: @escaping (Data) throws -> U) -> Result { if let responseError = responseError { guard let parseError = responseError as? ParseError else { - return .failure(ParseError(code: .invalidServerResponse, + return .failure(ParseError(code: .unknownError, message: "Unable to sync with parse-server: \(responseError)")) } return .failure(parseError) @@ -69,7 +69,7 @@ extension URLSession { mapper: @escaping (Data) throws -> U) -> Result { if let responseError = responseError { guard let parseError = responseError as? ParseError else { - return .failure(ParseError(code: .invalidServerResponse, + return .failure(ParseError(code: .unknownError, message: "Unable to sync with parse-server: \(responseError)")) } return .failure(parseError) diff --git a/Sources/ParseSwift/Types/ParseError.swift b/Sources/ParseSwift/Types/ParseError.swift index c1b45aee9..33de9d4aa 100644 --- a/Sources/ParseSwift/Types/ParseError.swift +++ b/Sources/ParseSwift/Types/ParseError.swift @@ -26,6 +26,7 @@ public struct ParseError: ParseType, Decodable, Swift.Error { as `code` for `Error` for callbacks on all classes. */ public enum Code: Int, Swift.Error, Codable { + /** Internal SDK Error. No information available */ @@ -35,191 +36,248 @@ public struct ParseError: ParseType, Decodable, Swift.Error { Internal server error. No information available. */ case internalServer = 1 + /** The connection to the Parse servers failed. */ case connectionFailed = 100 + /** Object doesn't exist, or has an incorrect password. */ case objectNotFound = 101 + /** You tried to find values matching a datatype that doesn't support exact database matching, like an array or a dictionary. */ case invalidQuery = 102 + /** Missing or invalid classname. Classnames are case-sensitive. They must start with a letter, and `a-zA-Z0-9_` are the only valid characters. */ case invalidClassName = 103 + /** Missing object id. */ case missingObjectId = 104 + /** Invalid key name. Keys are case-sensitive. They must start with a letter, and `a-zA-Z0-9_` are the only valid characters. */ case invalidKeyName = 105 + /** Malformed pointer. Pointers must be arrays of a classname and an object id. */ case invalidPointer = 106 + /** Malformed json object. A json dictionary is expected. */ case invalidJSON = 107 + /** Tried to access a feature only available internally. */ case commandUnavailable = 108 + /** Field set to incorrect type. */ case incorrectType = 111 + /** Invalid channel name. A channel name is either an empty string (the broadcast channel) or contains only `a-zA-Z0-9_` characters and starts with a letter. */ case invalidChannelName = 112 + /** Invalid device token. */ case invalidDeviceToken = 114 + /** Push is misconfigured. See details to find out how. */ case pushMisconfigured = 115 + /** The object is too large. */ case objectTooLarge = 116 + /** That operation isn't allowed for clients. */ case operationForbidden = 119 + /** The results were not found in the cache. */ case cacheMiss = 120 + /** Keys in `NSDictionary` values may not include `$` or `.`. */ case invalidNestedKey = 121 + /** Invalid file name. A file name can contain only `a-zA-Z0-9_.` characters and should be between 1 and 36 characters. */ case invalidFileName = 122 + /** Invalid ACL. An ACL with an invalid format was saved. This should not happen if you use `ACL`. */ case invalidACL = 123 + /** The request timed out on the server. Typically this indicates the request is too expensive. */ case timeout = 124 + /** The email address was invalid. */ case invalidEmailAddress = 125 + /** - A unique field was given a value that is already taken. - */ - case duplicateValue = 137 - /** - Role's name is invalid. + Missing content type. */ - case invalidRoleName = 139 + case missingContentType = 126 + /** - Exceeded an application quota. Upgrade to resolve. + Missing content length. */ - case exceededQuota = 140 + case missingContentLength = 127 + /** - Cloud Code script had an error. + Invalid content length. */ - case scriptError = 141 + case invalidContentLength = 128 + /** - Cloud Code validation failed. + File was too large. */ - case validationError = 142 + case fileTooLarge = 129 + /** - Product purchase receipt is missing. + Failure saving a file. */ - case receiptMissing = 143 + case fileSaveFailure = 130 + /** - Product purchase receipt is invalid. + A unique field was given a value that is already taken. */ - case invalidPurchaseReceipt = 144 + case duplicateValue = 137 + /** - Payment is disabled on this device. + Role's name is invalid. */ - case paymentDisabled = 145 + case invalidRoleName = 139 + /** - The product identifier is invalid. + Exceeded an application quota. Upgrade to resolve. */ - case invalidProductIdentifier = 146 + case exceededQuota = 140 + /** - The product is not found in the App Store. + Cloud Code script had an error. */ - case productNotFoundInAppStore = 147 + case scriptFailed = 141 + /** - The Apple server response is not valid. + Cloud Code validation failed. */ - case invalidServerResponse = 148 + case validationFailed = 142 + /** - Product fails to download due to file system error. + Fail to convert data to image. */ - case productDownloadFileSystemFailure = 149 + case invalidImageData = 143 + /** - Fail to convert data to image. + Unsaved file failure. */ - case invalidImageData = 150 + case unsavedFileFailure = 151 + /** - Unsaved file. + An invalid push time. */ - case unsavedFile = 151 + case invalidPushTime = 152 + /** Fail to delete file. */ case fileDeleteFailure = 153 + + /** + Fail to delete an unnamed file. + */ + case fileDeleteUnnamedFailure = 161 + /** Application has exceeded its request limit. */ case requestLimitExceeded = 155 + + /** + The request was a duplicate and has been discarded + due to idempotency rules. + */ + case duplicateRequest = 159 + /** Invalid event name. */ case invalidEventName = 160 + + /** + Invalid value. + */ + case invalidValue = 162 + /** Username is missing or empty. */ case usernameMissing = 200 + /** Password is missing or empty. */ case userPasswordMissing = 201 + /** Username has already been taken. */ case usernameTaken = 202 + /** Email has already been taken. */ case userEmailTaken = 203 + /** The email is missing, and must be specified. */ case userEmailMissing = 204 + /** A user with the specified email was not found. */ case userWithEmailNotFound = 205 + /** The user cannot be altered by a client without the session. */ case userCannotBeAlteredWithoutSession = 206 + /** Users can only be created through sign up. */ @@ -229,11 +287,22 @@ public struct ParseError: ParseType, Decodable, Swift.Error { An existing account already linked to another user. */ case accountAlreadyLinked = 208 + /** - Error code indicating that the current session token is invalid. + The current session token is invalid. */ case invalidSessionToken = 209 + /** + Error enabling or verifying MFA. + */ + case mfaError = 210 + + /** + A valid MFA token must be provided. + */ + case mfaTokenRequired = 211 + /** Linked id missing from request. */ diff --git a/Tests/ParseSwiftTests/APICommandTests.swift b/Tests/ParseSwiftTests/APICommandTests.swift index c3b917aef..114972d76 100644 --- a/Tests/ParseSwiftTests/APICommandTests.swift +++ b/Tests/ParseSwiftTests/APICommandTests.swift @@ -142,7 +142,7 @@ class APICommandTests: XCTestCase { //This is less common as the HTTP won't be able to produce ParseErrors directly, but used for testing func testErrorHTTPReturnsParseError1() { - let originalError = ParseError(code: .invalidServerResponse, message: "Couldn't decode") + let originalError = ParseError(code: .unknownError, message: "Couldn't decode") MockURLProtocol.mockRequests { _ in return MockURLResponse(error: originalError) } diff --git a/Tests/ParseSwiftTests/ParseCloudTests.swift b/Tests/ParseSwiftTests/ParseCloudTests.swift index f43ef4cbc..335833450 100644 --- a/Tests/ParseSwiftTests/ParseCloudTests.swift +++ b/Tests/ParseSwiftTests/ParseCloudTests.swift @@ -165,7 +165,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length func testFunctionError() { - let parseError = ParseError(code: .scriptError, message: "Error: Invalid function") + let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function") let encoded: Data! do { @@ -245,7 +245,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length } func testFunctionMainQueueError() { - let parseError = ParseError(code: .scriptError, message: "Error: Invalid function") + let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function") MockURLProtocol.mockRequests { _ in do { @@ -322,7 +322,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length func testJobError() { - let parseError = ParseError(code: .scriptError, message: "Error: Invalid function") + let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function") let encoded: Data! do { @@ -402,7 +402,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length } func testJobMainQueueError() { - let parseError = ParseError(code: .scriptError, message: "Error: Invalid function") + let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function") MockURLProtocol.mockRequests { _ in do { From ce12a1a671058fc1b0ea325ba98ba6838a0d4f37 Mon Sep 17 00:00:00 2001 From: Corey Date: Wed, 14 Apr 2021 11:37:09 -0400 Subject: [PATCH 2/2] Update .codecov.yml --- .codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codecov.yml b/.codecov.yml index 9d8475330..3af28fb7d 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -5,7 +5,7 @@ coverage: status: patch: default: - target: auto + target: 49 changes: false project: default: