Skip to content

Commit 879055b

Browse files
authored
fix: some async/await methods won't throw errors (#334)
* refactor: remove force unwrapping * fix async void returns * add change log * improve codecov * Update .codecov.yml
1 parent d2de796 commit 879055b

17 files changed

+328
-40
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: 78
1010
changes: false
1111
project:
1212
default:

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### main
44

5-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.2...main)
5+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.0.0...main)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

88
### 4.0.0
@@ -32,6 +32,7 @@ __Improvements__
3232
- (Breaking Change) Change the following method parameter names: isUsingTransactions -> usingTransactions, isAllowingCustomObjectIds -> allowingCustomObjectIds, isUsingEqualQueryConstraint -> usingEqualQueryConstraint, isMigratingFromObjcSDK -> migratingFromObjcSDK, isDeletingKeychainIfNeeded -> deletingKeychainIfNeeded ([#323](https://github.com/parse-community/Parse-Swift/pull/323)), thanks to [Corey Baker](https://github.com/cbaker6).
3333

3434
__Fixes__
35+
- Async/await methods that return void would no throw errors received from server ([#334](https://github.com/parse-community/Parse-Swift/pull/334)), thanks to [Corey Baker](https://github.com/cbaker6).
3536
- Always check for ParseError first when decoding responses from the server. Before this fix, this could cause issues depending on how calls are made from the Swift SDK ([#332](https://github.com/parse-community/Parse-Swift/pull/332)), thanks to [Corey Baker](https://github.com/cbaker6).
3637

3738
### 3.1.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import PackageDescription
5757
let package = Package(
5858
name: "YOUR_PROJECT_NAME",
5959
dependencies: [
60-
.package(url: "https://github.com/parse-community/Parse-Swift", from: "3.1.2"),
60+
.package(url: "https://github.com/parse-community/Parse-Swift", .upToNextMajor(from: "4.0.0")),
6161
]
6262
)
6363
```

Sources/ParseSwift/Objects/ParseInstallation+async.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ public extension ParseInstallation {
114114
- important: If an object deleted has the same objectId as current, it will automatically update the current.
115115
*/
116116
func delete(options: API.Options = []) async throws {
117-
_ = try await withCheckedThrowingContinuation { continuation in
117+
let result = try await withCheckedThrowingContinuation { continuation in
118118
self.delete(options: options, completion: continuation.resume)
119119
}
120+
if case let .failure(error) = result {
121+
throw error
122+
}
120123
}
121124
}
122125

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,12 @@ extension ParseInstallation {
406406

407407
var foundCurrentInstallationObjects = results.filter { $0.hasSameInstallationId(as: currentInstallation) }
408408
foundCurrentInstallationObjects = try foundCurrentInstallationObjects.sorted(by: {
409-
if $0.updatedAt == nil || $1.updatedAt == nil {
409+
guard let firstUpdatedAt = $0.updatedAt,
410+
let secondUpdatedAt = $1.updatedAt else {
410411
throw ParseError(code: .unknownError,
411-
message: "Objects from the server should always have an 'updatedAt'")
412+
message: "Objects from the server should always have an \"updatedAt\"")
412413
}
413-
return $0.updatedAt!.compare($1.updatedAt!) == .orderedDescending
414+
return firstUpdatedAt.compare(secondUpdatedAt) == .orderedDescending
414415
})
415416
if let foundCurrentInstallation = foundCurrentInstallationObjects.first {
416417
if !deleting {

Sources/ParseSwift/Objects/ParseObject+async.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ public extension ParseObject {
9696
- throws: An error of type `ParseError`.
9797
*/
9898
func delete(options: API.Options = []) async throws {
99-
_ = try await withCheckedThrowingContinuation { continuation in
99+
let result = try await withCheckedThrowingContinuation { continuation in
100100
self.delete(options: options,
101101
completion: continuation.resume)
102102
}
103+
if case let .failure(error) = result {
104+
throw error
105+
}
103106
}
104107
}
105108

Sources/ParseSwift/Objects/ParseUser+async.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ public extension ParseUser {
101101
- throws: An error of type `ParseError`.
102102
*/
103103
static func logout(options: API.Options = []) async throws {
104-
_ = try await withCheckedThrowingContinuation { continuation in
104+
let result = try await withCheckedThrowingContinuation { continuation in
105105
Self.logout(options: options, completion: continuation.resume)
106106
}
107+
if case let .failure(error) = result {
108+
throw error
109+
}
107110
}
108111

109112
/**
@@ -115,9 +118,12 @@ public extension ParseUser {
115118
*/
116119
static func passwordReset(email: String,
117120
options: API.Options = []) async throws {
118-
_ = try await withCheckedThrowingContinuation { continuation in
121+
let result = try await withCheckedThrowingContinuation { continuation in
119122
Self.passwordReset(email: email, options: options, completion: continuation.resume)
120123
}
124+
if case let .failure(error) = result {
125+
throw error
126+
}
121127
}
122128

123129
/**
@@ -147,9 +153,12 @@ public extension ParseUser {
147153
*/
148154
static func verificationEmail(email: String,
149155
options: API.Options = []) async throws {
150-
_ = try await withCheckedThrowingContinuation { continuation in
156+
let result = try await withCheckedThrowingContinuation { continuation in
151157
Self.verificationEmail(email: email, options: options, completion: continuation.resume)
152158
}
159+
if case let .failure(error) = result {
160+
throw error
161+
}
153162
}
154163

155164
/**
@@ -252,9 +261,12 @@ public extension ParseUser {
252261
- important: If an object deleted has the same objectId as current, it will automatically update the current.
253262
*/
254263
func delete(options: API.Options = []) async throws {
255-
_ = try await withCheckedThrowingContinuation { continuation in
264+
let result = try await withCheckedThrowingContinuation { continuation in
256265
self.delete(options: options, completion: continuation.resume)
257266
}
267+
if case let .failure(error) = result {
268+
throw error
269+
}
258270
}
259271
}
260272

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,17 +494,8 @@ extension ParseUser {
494494
completion: @escaping (Result<Self, ParseError>) -> Void) {
495495
var options = options
496496
options.insert(.cachePolicy(.reloadIgnoringLocalCacheData))
497-
let username: String!
498-
if let current = BaseParseUser.current,
499-
let currentUsername = current.username {
500-
username = currentUsername
501-
} else {
502-
username = ""
503-
}
504-
var method: API.Method = .POST
505-
if !usingPost {
506-
method = .GET
507-
}
497+
let username = BaseParseUser.current?.username ?? ""
498+
let method: API.Method = usingPost ? .POST : .GET
508499
verifyPasswordCommand(username: username,
509500
password: password,
510501
method: method)
@@ -532,10 +523,7 @@ extension ParseUser {
532523
path: .verifyPassword,
533524
params: params,
534525
body: loginBody) { (data) -> Self in
535-
var sessionToken = ""
536-
if let currentSessionToken = BaseParseUser.current?.sessionToken {
537-
sessionToken = currentSessionToken
538-
}
526+
var sessionToken = BaseParseUser.current?.sessionToken ?? ""
539527
if let decodedSessionToken = try? ParseCoding.jsonDecoder()
540528
.decode(LoginSignupResponse.self, from: data).sessionToken {
541529
sessionToken = decodedSessionToken
@@ -826,11 +814,12 @@ extension ParseUser {
826814

827815
var foundCurrentUserObjects = results.filter { $0.hasSameObjectId(as: currentUser) }
828816
foundCurrentUserObjects = try foundCurrentUserObjects.sorted(by: {
829-
if $0.updatedAt == nil || $1.updatedAt == nil {
817+
guard let firstUpdatedAt = $0.updatedAt,
818+
let secondUpdatedAt = $1.updatedAt else {
830819
throw ParseError(code: .unknownError,
831-
message: "Objects from the server should always have an 'updatedAt'")
820+
message: "Objects from the server should always have an \"updatedAt\"")
832821
}
833-
return $0.updatedAt!.compare($1.updatedAt!) == .orderedDescending
822+
return firstUpdatedAt.compare(secondUpdatedAt) == .orderedDescending
834823
})
835824
if let foundCurrentUser = foundCurrentUserObjects.first {
836825
if !deleting {

Sources/ParseSwift/Types/ParseAnalytics+async.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ public extension ParseAnalytics {
3434
static func trackAppOpened(launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
3535
at date: Date? = nil,
3636
options: API.Options = []) async throws {
37-
_ = try await withCheckedThrowingContinuation { continuation in
37+
let result = try await withCheckedThrowingContinuation { continuation in
3838
Self.trackAppOpened(launchOptions: launchOptions,
3939
at: date,
4040
options: options,
4141
completion: continuation.resume)
4242
}
43+
if case let .failure(error) = result {
44+
throw error
45+
}
4346
}
4447
#endif
4548

@@ -58,12 +61,15 @@ public extension ParseAnalytics {
5861
static func trackAppOpened(dimensions: [String: String]? = nil,
5962
at date: Date? = nil,
6063
options: API.Options = []) async throws {
61-
_ = try await withCheckedThrowingContinuation { continuation in
64+
let result = try await withCheckedThrowingContinuation { continuation in
6265
Self.trackAppOpened(dimensions: dimensions,
6366
at: date,
6467
options: options,
6568
completion: continuation.resume)
6669
}
70+
if case let .failure(error) = result {
71+
throw error
72+
}
6773
}
6874

6975
/**
@@ -73,10 +79,13 @@ public extension ParseAnalytics {
7379
- throws: An error of type `ParseError`.
7480
*/
7581
func track(options: API.Options = []) async throws {
76-
_ = try await withCheckedThrowingContinuation { continuation in
82+
let result = try await withCheckedThrowingContinuation { continuation in
7783
self.track(options: options,
7884
completion: continuation.resume)
7985
}
86+
if case let .failure(error) = result {
87+
throw error
88+
}
8089
}
8190

8291
/**

Sources/ParseSwift/Types/ParseFile+async.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ public extension ParseFile {
9696
- throws: An error of type `ParseError`.
9797
*/
9898
func delete(options: API.Options = []) async throws {
99-
_ = try await withCheckedThrowingContinuation { continuation in
99+
let result = try await withCheckedThrowingContinuation { continuation in
100100
self.delete(options: options, completion: continuation.resume)
101101
}
102+
if case let .failure(error) = result {
103+
throw error
104+
}
102105
}
103106
}
104107

Tests/ParseSwiftTests/APICommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class APICommandTests: XCTestCase {
185185
}
186186
}
187187

188-
//This is how errors HTTP errors should typically come in
188+
// This is how errors HTTP errors should typically come in
189189
func testErrorHTTP400JSON() {
190190
let parseError = ParseError(code: .connectionFailed, message: "Connection failed")
191191
let errorKey = "error"

0 commit comments

Comments
 (0)