-
Notifications
You must be signed in to change notification settings - Fork 41
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
Change parseEntity
to not wrap errors thrown by Decoders and Decodables.
#29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. | |
|
||
#### 2.x Releases | ||
|
||
* `2.2.x` Releases = [2.2.0](#220) | [2.2.1](#221) | ||
* `2.2.x` Releases = [2.2.0](#220) | [2.2.1](#221) | [2.2.2](#222) | ||
* `2.1.x` Releases = [2.1.0](#210) | ||
* `2.0.x` Releases = [2.0.0](#200) | ||
|
||
|
@@ -16,6 +16,13 @@ All notable changes to this project will be documented in this file. | |
|
||
--- | ||
|
||
## [2.2.2](https://github.com/Nike-Inc/Elevate/releases/tag/2.2.2) | ||
|
||
Released on 2017-06-22. All issues associated with this milestone can be found using this | ||
[filter](https://github.com/Nike-Inc/Elevate/milestone/5?closed=1). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's switch this over to |
||
|
||
--- | ||
|
||
## [2.2.1](https://github.com/Nike-Inc/Elevate/releases/tag/2.2.1) | ||
|
||
Released on 2017-02-09. All issues associated with this milestone can be found using this | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,15 @@ public class Parser { | |
/// - closure: Defines the property list for the parser via the passed in `Schema` instance. | ||
/// | ||
/// - Returns: The parsed entity as a Dictionary. | ||
/// | ||
/// - Throws: `ParserError` for parsing related errors or `Error`s thrown by custom `Decodable` and `Decoder` implementations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can condense this wording a bit. |
||
public class func parseEntity(data: Data, closure: (Schema) -> Void) throws -> [String: Any] { | ||
let result: [String: Any] | ||
let json: Any | ||
|
||
// A JSONSerialization error will be converted to ParserError | ||
do { | ||
let json = try JSONSerialization.jsonObject(with: data, options: []) | ||
result = try parseEntity(json: json, closure: closure) | ||
json = try JSONSerialization.jsonObject(with: data, options: []) | ||
} catch { | ||
if error is ParserError { | ||
throw error | ||
|
@@ -60,6 +63,8 @@ public class Parser { | |
} | ||
} | ||
|
||
result = try parseEntity(json: json, closure: closure) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just get rid of the do-catch here. |
||
|
||
return result | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,25 @@ class DecodableTestCase: BaseTestCase { | |
decodableErrorTest(type: [String: String].self, value: "1") | ||
} | ||
|
||
func testThatThrownCustomErrorsCanBeCaught() { | ||
do { | ||
// Given | ||
let data = loadJSONDataForFileNamed("PropertyTypesTest") | ||
|
||
// When | ||
let _: ErrorThrowingDecodable = try Elevate.decodeObject(from: data) | ||
|
||
XCTFail("Decoding unexpectedly succeeded.") | ||
} catch let error as NSError { | ||
// Then | ||
XCTAssertEqual(error.domain, "Decodable Test Error", "Error domain did not match expected value.") | ||
XCTAssertEqual(error.code, 42, "Error code did not match expected value.") | ||
} catch { | ||
XCTFail("Parser error was of incorrect type.") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should switch over to using the |
||
} | ||
} | ||
|
||
// MARK: - Private - Helper Methods | ||
|
||
private func decodableErrorTest(type: Decodable.Type, value: Any) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,4 +261,23 @@ class DateDecoderTestCase: BaseTestCase { | |
XCTFail("Parser error was of incorrect type") | ||
} | ||
} | ||
|
||
func testThatThrownCustomErrorsCanBeCaught() { | ||
do { | ||
// Given | ||
let data = loadJSONDataForFileNamed("PropertyTypesTest") | ||
|
||
// When | ||
let _: ErrorThrowingDecodable = try Elevate.decodeObject(from: data, with: ErrorThrowingDecoder()) | ||
|
||
XCTFail("Decoding unexpectedly succeeded.") | ||
} catch let error as NSError { | ||
// Then | ||
XCTAssertEqual(error.domain, "Decoder Test Error", "Error domain did not match expected value.") | ||
XCTAssertEqual(error.code, 42, "Error code did not match expected value.") | ||
} catch { | ||
XCTFail("Parser error was of incorrect type.") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should switch over to using the |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revert this since there's going to be another PR going into
2.2.2
.