Skip to content

Commit c500288

Browse files
authored
refactor: add and update ParseError codes (#24)
* refactor: update ParseError codes * add test * update images * lower codecov patch
1 parent bf06c12 commit c500288

File tree

93 files changed

+547
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+547
-505
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ coverage:
66
status:
77
patch:
88
default:
9-
target: auto
9+
target: 49
1010
changes: false
1111
project:
1212
default:

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ concurrency:
1616

1717
jobs:
1818
xcode-test-ios:
19+
timeout-minutes: 15
1920
runs-on: macos-latest
2021
steps:
2122
- uses: actions/checkout@v3
@@ -43,6 +44,7 @@ jobs:
4344
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
4445

4546
xcode-test-macos:
47+
timeout-minutes: 15
4648
runs-on: macos-latest
4749
steps:
4850
- uses: actions/checkout@v3
@@ -76,6 +78,7 @@ jobs:
7678
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
7779

7880
xcode-test-tvos:
81+
timeout-minutes: 15
7982
runs-on: macos-latest
8083
steps:
8184
- uses: actions/checkout@v3
@@ -103,6 +106,7 @@ jobs:
103106
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
104107

105108
xcode-build-watchos:
109+
timeout-minutes: 15
106110
runs-on: macos-latest
107111
steps:
108112
- uses: actions/checkout@v3
@@ -120,6 +124,7 @@ jobs:
120124
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
121125

122126
spm-test:
127+
timeout-minutes: 15
123128
runs-on: macos-latest
124129
steps:
125130
- uses: actions/checkout@v3
@@ -153,6 +158,7 @@ jobs:
153158
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
154159

155160
xcode-test-ios-5_3:
161+
timeout-minutes: 15
156162
needs: xcode-build-watchos
157163
runs-on: macos-11
158164
steps:
@@ -177,6 +183,7 @@ jobs:
177183
DEVELOPER_DIR: ${{ env.CI_XCODE_OLDEST }}
178184

179185
linux:
186+
timeout-minutes: 5
180187
runs-on: ubuntu-18.04
181188
steps:
182189
- uses: actions/checkout@v3
@@ -197,6 +204,7 @@ jobs:
197204
fail_ci_if_error: true
198205

199206
windows:
207+
timeout-minutes: 10
200208
runs-on: windows-2019
201209
steps:
202210
- uses: actions/checkout@v3
@@ -214,6 +222,7 @@ jobs:
214222
fail_ci_if_error: false
215223

216224
windows-latest:
225+
timeout-minutes: 10
217226
runs-on: windows-latest
218227
steps:
219228
- uses: actions/checkout@v3
@@ -231,6 +240,7 @@ jobs:
231240
fail_ci_if_error: false
232241

233242
docs:
243+
timeout-minutes: 10
234244
needs: xcode-build-watchos
235245
runs-on: macos-latest
236246
steps:
@@ -243,6 +253,7 @@ jobs:
243253
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
244254

245255
carthage:
256+
timeout-minutes: 25
246257
needs: xcode-build-watchos
247258
runs-on: macos-latest
248259
steps:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.16.2...5.0.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.0.0/documentation/parseswift)
99

1010
__Fixes__
11+
- (Breaking Change) Add and update ParseError codes. unknownError has been renamed to otherCause. invalidImageData now has the error code of 150. webhookError has the error code of 143 ([#23](https://github.com/netreconlab/Parse-Swift/pull/23)), thanks to [Corey Baker](https://github.com/cbaker6).
1112
- (Breaking Change) Remove deprecated code ([#23](https://github.com/netreconlab/Parse-Swift/pull/23)), thanks to [Corey Baker](https://github.com/cbaker6).
1213

1314
### 4.16.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![parse-repository-header-sdk-swift](Sources/ParseSwift/Documentation.docc/Resources/parse-swift.png)
1+
![parse-swift](https://user-images.githubusercontent.com/8621344/204069535-e1882bb0-bbcb-4178-87e6-58fd1bed96d1.png)
22

33
<h3 align="center">iOS · macOS · watchOS · tvOS · Linux · Android · Windows</h3>
44

Sources/ParseSwift/API/API+Command.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal extension API {
111111
group.wait()
112112

113113
guard let response = responseResult else {
114-
throw ParseError(code: .unknownError,
114+
throw ParseError(code: .otherCause,
115115
message: "Could not unrwrap server response")
116116
}
117117
return try response.get()
@@ -265,7 +265,7 @@ internal extension API {
265265
}
266266
} else {
267267
callbackQueue.async {
268-
completion(.failure(ParseError(code: .unknownError,
268+
completion(.failure(ParseError(code: .otherCause,
269269
// swiftlint:disable:next line_length
270270
message: "Cannot download the file without specifying the url")))
271271
}
@@ -288,13 +288,13 @@ internal extension API {
288288
Parse.configuration.serverURL.appendingPathComponent(path.urlComponent) : parseURL!
289289

290290
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
291-
return .failure(ParseError(code: .unknownError,
291+
return .failure(ParseError(code: .otherCause,
292292
message: "Could not unrwrap url components for \(url)"))
293293
}
294294
components.queryItems = params
295295

296296
guard let urlComponents = components.url else {
297-
return .failure(ParseError(code: .unknownError,
297+
return .failure(ParseError(code: .otherCause,
298298
message: "Could not create url from components for \(components)"))
299299
}
300300

@@ -303,7 +303,7 @@ internal extension API {
303303
if let urlBody = body {
304304
if (urlBody as? ParseCloudTypeable) != nil {
305305
guard let bodyData = try? ParseCoding.parseEncoder().encode(urlBody, skipKeys: .cloud) else {
306-
return .failure(ParseError(code: .unknownError,
306+
return .failure(ParseError(code: .otherCause,
307307
message: "Could not encode body \(urlBody)"))
308308
}
309309
urlRequest.httpBody = bodyData
@@ -315,7 +315,7 @@ internal extension API {
315315
collectChildren: false,
316316
objectsSavedBeforeThisOne: childObjects,
317317
filesSavedBeforeThisOne: childFiles) else {
318-
return .failure(ParseError(code: .unknownError,
318+
return .failure(ParseError(code: .otherCause,
319319
message: "Could not encode body \(urlBody)"))
320320
}
321321
urlRequest.httpBody = bodyData.encoded
@@ -349,7 +349,7 @@ internal extension API.Command {
349349
if !object.isSaved {
350350
return createFile(object)
351351
} else {
352-
throw ParseError(code: .unknownError,
352+
throw ParseError(code: .otherCause,
353353
message: "File is already saved and cannot be updated.")
354354
}
355355
}
@@ -372,7 +372,7 @@ internal extension API.Command {
372372
otherURL: object.cloudURL) { (data) -> ParseFile in
373373
let tempFileLocation = try ParseCoding.jsonDecoder().decode(URL.self, from: data)
374374
guard let fileManager = ParseFileManager() else {
375-
throw ParseError(code: .unknownError, message: "Cannot create fileManager")
375+
throw ParseError(code: .otherCause, message: "Cannot create fileManager")
376376
}
377377
let downloadDirectoryPath = try ParseFileManager.downloadDirectory()
378378
try fileManager.createDirectoryIfNeeded(downloadDirectoryPath.relativePath)
@@ -542,22 +542,22 @@ internal extension API.Command where T: ParseObject {
542542
return .success(updatedObject)
543543
} catch {
544544
guard let parseError = error as? ParseError else {
545-
return .failure(ParseError(code: .unknownError,
545+
return .failure(ParseError(code: .otherCause,
546546
message: error.localizedDescription))
547547
}
548548
return .failure(parseError)
549549
}
550550
} else {
551551
guard let parseError = response.error else {
552-
return .failure(ParseError(code: .unknownError, message: "unknown error"))
552+
return .failure(ParseError(code: .otherCause, message: "unknown error"))
553553
}
554554

555555
return .failure(parseError)
556556
}
557557
})
558558
} catch {
559559
guard let parseError = error as? ParseError else {
560-
return [(.failure(ParseError(code: .unknownError, message: "decoding error: \(error)")))]
560+
return [(.failure(ParseError(code: .otherCause, message: "decoding error: \(error)")))]
561561
}
562562
return [(.failure(parseError))]
563563
}
@@ -588,15 +588,15 @@ internal extension API.Command where T: ParseObject {
588588
return .success(())
589589
} else {
590590
guard let parseError = response.error else {
591-
return .failure(ParseError(code: .unknownError, message: "unknown error"))
591+
return .failure(ParseError(code: .otherCause, message: "unknown error"))
592592
}
593593

594594
return .failure(parseError)
595595
}
596596
})
597597
} catch {
598598
guard let parseError = error as? ParseError else {
599-
return [(.failure(ParseError(code: .unknownError, message: "decoding error: \(error)")))]
599+
return [(.failure(ParseError(code: .otherCause, message: "decoding error: \(error)")))]
600600
}
601601
return [(.failure(parseError))]
602602
}

Sources/ParseSwift/API/API+NonParseBodyCommand.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal extension API {
5050
group.wait()
5151

5252
guard let response = responseResult else {
53-
throw ParseError(code: .unknownError,
53+
throw ParseError(code: .otherCause,
5454
message: "Could not unrwrap server response")
5555
}
5656
return try response.get()
@@ -93,21 +93,21 @@ internal extension API {
9393
let url = Parse.configuration.serverURL.appendingPathComponent(path.urlComponent)
9494

9595
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
96-
return .failure(ParseError(code: .unknownError,
96+
return .failure(ParseError(code: .otherCause,
9797
message: "Could not unrwrap url components for \(url)"))
9898
}
9999
components.queryItems = params
100100

101101
guard let urlComponents = components.url else {
102-
return .failure(ParseError(code: .unknownError,
102+
return .failure(ParseError(code: .otherCause,
103103
message: "Could not create url from components for \(components)"))
104104
}
105105

106106
var urlRequest = URLRequest(url: urlComponents)
107107
urlRequest.allHTTPHeaderFields = headers
108108
if let urlBody = body {
109109
guard let bodyData = try? ParseCoding.jsonEncoder().encode(urlBody) else {
110-
return .failure(ParseError(code: .unknownError,
110+
return .failure(ParseError(code: .otherCause,
111111
message: "Could not encode body \(urlBody)"))
112112
}
113113
urlRequest.httpBody = bodyData
@@ -128,7 +128,7 @@ internal extension API.NonParseBodyCommand {
128128
// MARK: Deleting
129129
static func delete<T>(_ object: T) throws -> API.NonParseBodyCommand<NoBody, NoBody> where T: ParseObject {
130130
guard object.isSaved else {
131-
throw ParseError(code: .unknownError,
131+
throw ParseError(code: .otherCause,
132132
message: "Cannot delete an object without an objectId")
133133
}
134134

@@ -192,19 +192,19 @@ internal extension API.NonParseBodyCommand {
192192
let response = responses[object.offset]
193193
if let success = response.success {
194194
guard let successfulResponse = try? object.element.mapper(success) else {
195-
return.failure(ParseError(code: .unknownError, message: "unknown error"))
195+
return.failure(ParseError(code: .otherCause, message: "unknown error"))
196196
}
197197
return .success(successfulResponse)
198198
} else {
199199
guard let parseError = response.error else {
200-
return .failure(ParseError(code: .unknownError, message: "unknown error"))
200+
return .failure(ParseError(code: .otherCause, message: "unknown error"))
201201
}
202202
return .failure(parseError)
203203
}
204204
})
205205
} catch {
206206
guard let parseError = error as? ParseError else {
207-
return [(.failure(ParseError(code: .unknownError, message: "decoding error: \(error)")))]
207+
return [(.failure(ParseError(code: .otherCause, message: "decoding error: \(error)")))]
208208
}
209209
return [(.failure(parseError))]
210210
}

Sources/ParseSwift/API/Responses.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal struct ReplaceResponse: Decodable {
3535
}
3636
guard let createdAt = createdAt else {
3737
guard let updatedAt = updatedAt else {
38-
throw ParseError(code: .unknownError,
38+
throw ParseError(code: .otherCause,
3939
message: "Response from server should not have an updatedAt of nil")
4040
}
4141
return UpdateResponse(updatedAt: updatedAt).apply(to: object)
@@ -77,7 +77,7 @@ internal struct BatchResponse: Codable {
7777
message: "Response from server should not have an objectId of nil")
7878
}
7979
guard let createdAt = createdAt else {
80-
throw ParseError(code: .unknownError,
80+
throw ParseError(code: .otherCause,
8181
message: "Response from server should not have an createdAt of nil")
8282
}
8383
return CreateResponse(objectId: objectId, createdAt: createdAt)
@@ -89,7 +89,7 @@ internal struct BatchResponse: Codable {
8989

9090
func asUpdateResponse() throws -> UpdateResponse {
9191
guard let updatedAt = updatedAt else {
92-
throw ParseError(code: .unknownError,
92+
throw ParseError(code: .otherCause,
9393
message: "Response from server should not have an updatedAt of nil")
9494
}
9595
return UpdateResponse(updatedAt: updatedAt)

Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
3131
func makeDictionary(user: String,
3232
identityToken: Data) throws -> [String: String] {
3333
guard let identityTokenString = String(data: identityToken, encoding: .utf8) else {
34-
throw ParseError(code: .unknownError, message: "Could not convert identityToken to String")
34+
throw ParseError(code: .otherCause, message: "Could not convert identityToken to String")
3535
}
3636
return [AuthenticationKeys.id.rawValue: user,
3737
AuthenticationKeys.token.rawValue: identityTokenString]
@@ -74,7 +74,7 @@ public extension ParseApple {
7474

7575
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
7676
callbackQueue.async {
77-
completion(.failure(.init(code: .unknownError,
77+
completion(.failure(.init(code: .otherCause,
7878
message: "Could not create authData.")))
7979
}
8080
return
@@ -91,7 +91,7 @@ public extension ParseApple {
9191
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
9292
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
9393
callbackQueue.async {
94-
completion(.failure(.init(code: .unknownError,
94+
completion(.failure(.init(code: .otherCause,
9595
message: "Should have authData in consisting of keys \"id\" and \"token\".")))
9696
}
9797
return
@@ -122,7 +122,7 @@ public extension ParseApple {
122122
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
123123
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
124124
callbackQueue.async {
125-
completion(.failure(.init(code: .unknownError,
125+
completion(.failure(.init(code: .otherCause,
126126
message: "Could not create authData.")))
127127
}
128128
return
@@ -138,7 +138,7 @@ public extension ParseApple {
138138
callbackQueue: DispatchQueue = .main,
139139
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
140140
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
141-
let error = ParseError(code: .unknownError,
141+
let error = ParseError(code: .otherCause,
142142
message: "Should have authData in consisting of keys \"id\" and \"token\".")
143143
callbackQueue.async {
144144
completion(.failure(error))

Sources/ParseSwift/Authentication/3rd Party/ParseFacebook/ParseFacebook.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public extension ParseFacebook {
136136
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
137137
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
138138
callbackQueue.async {
139-
completion(.failure(.init(code: .unknownError,
139+
completion(.failure(.init(code: .otherCause,
140140
message: "Should have authData in consisting of keys \"id\", \"expirationDate\" and \"authenticationToken\" or \"accessToken\".")))
141141
}
142142
return
@@ -210,7 +210,7 @@ public extension ParseFacebook {
210210
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
211211
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
212212
callbackQueue.async {
213-
completion(.failure(.init(code: .unknownError,
213+
completion(.failure(.init(code: .otherCause,
214214
message: "Should have authData in consisting of keys \"id\", \"expirationDate\" and \"authenticationToken\" or \"accessToken\".")))
215215
}
216216
return

Sources/ParseSwift/Authentication/3rd Party/ParseGithub/ParseGitHub.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public extension ParseGitHub {
8787
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
8888
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
8989
callbackQueue.async {
90-
completion(.failure(.init(code: .unknownError,
90+
completion(.failure(.init(code: .otherCause,
9191
message: "Should have authData in consisting of keys \"id\" and \"accessToken\".")))
9292
}
9393
return
@@ -131,7 +131,7 @@ public extension ParseGitHub {
131131
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
132132
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
133133
callbackQueue.async {
134-
completion(.failure(.init(code: .unknownError,
134+
completion(.failure(.init(code: .otherCause,
135135
message: "Should have authData in consisting of keys \"id\" and \"accessToken\".")))
136136
}
137137
return

0 commit comments

Comments
 (0)