Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add invalid struct error #238

Merged
merged 31 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5ebb164
new: allow for custom error codes from Parse Cloud
dblythy Jun 16, 2021
6012d2c
Update APICommandTests.swift
dblythy Jun 16, 2021
bc04fd1
Update ParseError.swift
dblythy Jun 16, 2021
e2675fa
fix lint
dblythy Jun 16, 2021
1e15c70
Decode parse otherCode error and add tests
cbaker6 Jun 16, 2021
c1f3ca8
Update Sources/ParseSwift/Types/ParseError.swift
dblythy Jun 17, 2021
8e9630d
add guard
dblythy Jun 17, 2021
be25ddb
Merge branch 'main' of https://github.com/dblythy/Parse-Swift into main
dblythy Jun 17, 2021
ae4eff6
Update Sources/ParseSwift/Types/ParseError.swift
dblythy Jun 17, 2021
076af88
Update Tests/ParseSwiftTests/ParseErrorTests.swift
dblythy Jun 17, 2021
0faebdc
Update CHANGELOG.md
dblythy Jun 17, 2021
af0d855
add invalid struct
dblythy Sep 20, 2021
20ba08b
change line length
dblythy Sep 20, 2021
0a1bf4a
Update URLSession+extensions.swift
dblythy Sep 20, 2021
cd9b806
change line length
dblythy Sep 20, 2021
f3ce270
Update ParseError.swift
dblythy Sep 20, 2021
889b3af
fix lint
dblythy Sep 20, 2021
6d91c07
Revert "fix lint"
dblythy Sep 20, 2021
4bde9e2
fix lint
dblythy Sep 20, 2021
53a2791
make changes
dblythy Sep 20, 2021
973a4c1
remove invalid struct
dblythy Sep 20, 2021
e0d51f0
Update URLSession+extensions.swift
dblythy Sep 20, 2021
68c2211
Update ParseQueryTests.swift
dblythy Oct 9, 2021
2be6646
Update ParseQueryTests.swift
dblythy Oct 9, 2021
191d1cd
Merge branch 'main' into invalid-struct
dblythy Oct 9, 2021
0b3f0f4
revert changes
dblythy Oct 9, 2021
f5af25c
Update ParseErrorTests.swift
dblythy Oct 9, 2021
a85aa72
Update ParseQueryTests.swift
dblythy Oct 9, 2021
f95bca2
Merge remote-tracking branch 'refs/remotes/parse/main'
cbaker6 Oct 9, 2021
a27b520
update podspec and change log
cbaker6 Oct 9, 2021
f9b27f8
remove localized error
cbaker6 Oct 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### main
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.4...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_
- Add more detail to invalid struct errors ([#238](https://github.com/parse-community/Parse-Swift/pull/211)), thanks to [Daniel Blyth](https://github.com/dblythy).

### 1.9.4
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.3...1.9.4)
Expand Down
4 changes: 4 additions & 0 deletions Sources/ParseSwift/API/URLSession+extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ extension URLSession {
let json = try? JSONSerialization
.data(withJSONObject: responseData,
options: .prettyPrinted) else {
let err = (error as NSError)
dblythy marked this conversation as resolved.
Show resolved Hide resolved
if err.code == 4865, let description = err.userInfo["NSDebugDescription"] {
return .failure(ParseError(code: .invalidStruct, message: "Invalid struct: \(description)"))
}
return .failure(ParseError(code: .unknownError,
// swiftlint:disable:next line_length
message: "Error decoding parse-server response: \(response) with error: \(error.localizedDescription) Format: \(String(describing: String(data: responseData, encoding: .utf8)))"))
Expand Down
1 change: 1 addition & 0 deletions Sources/ParseSwift/Types/CloudViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open class CloudViewModel<T: ParseCloud>: CloudObservable {
}

/// Updates and notifies when there is an error retrieving the results.
// swiftlint:disable:next redundant_optional_initialization
dblythy marked this conversation as resolved.
Show resolved Hide resolved
open var error: ParseError? = nil {
cbaker6 marked this conversation as resolved.
Show resolved Hide resolved
willSet {
if newValue != nil {
Expand Down
5 changes: 5 additions & 0 deletions Sources/ParseSwift/Types/ParseError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ public struct ParseError: ParseType, Decodable, Swift.Error {
*/
case xDomainRequest = 602

/**
Error code indicating the Parse Swift struct is invalid.
*/
case invalidStruct = 603
cbaker6 marked this conversation as resolved.
Show resolved Hide resolved

/**
Error code indicating any other custom error sent from the Parse Server.
*/
Expand Down
1 change: 1 addition & 0 deletions Sources/ParseSwift/Types/QueryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
}

/// Updates and notifies when there is an error retrieving the results.
// swiftlint:disable:next redundant_optional_initialization
dblythy marked this conversation as resolved.
Show resolved Hide resolved
open var error: ParseError? = nil {
dblythy marked this conversation as resolved.
Show resolved Hide resolved
willSet {
if newValue != nil {
Expand Down
12 changes: 12 additions & 0 deletions Tests/ParseSwiftTests/ParseQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,18 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
}

let query = GameScore.query()
do {
_ = try query.first(options: [])
XCTFail("Should have thrown error")
} catch {
guard let error = error as? ParseError else {
XCTFail("Should have casted as ParseError")
return
}
// swiftlint:disable:next line_length
XCTAssertEqual(error.message, "Invalid struct: No value associated with key CodingKeys(stringValue: \"score\", intValue: nil) (\"score\").")
cbaker6 marked this conversation as resolved.
Show resolved Hide resolved
XCTAssertEqual(error.code, .invalidStruct)
}
XCTAssertThrowsError(try query.first(options: []))
}

Expand Down