-
Notifications
You must be signed in to change notification settings - Fork 30
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
Make parsing initializers throw errors on failure #29
Comments
I think this one should be a more global approach and try to replace any I suggest changing this while writing tests but we need to find a way how to test We should create new |
@czechboy0 I think this one should be marked as a blocker right now because whatever we'll try to implement we'll be basing on exisinting |
In light of this, I suggest we slow down on migrating the JSON parsing initializers to |
I totally agree. The code looks cluttered and FUGLY as hell; would rather keep it «failable» but clean. |
This issue is now blocked, we're waiting for Swift to become sane about |
@czechboy0 perhaps remove the |
Good point 👍 |
I know that we are waiting for some Swift changes now, but when I run the test below with the func testDictionaryInit() {
XCTempAssertNoThrowError("Failed to initialize the server configuration") {
let json = [
"host": "//\\https://127.0.0.1",
"user": "ICanCreateBots",
"password": "superSecr3t"
]
let config = try XcodeServerConfig(json: json)
XCTAssertEqual(config!.host, "https://127.0.0.1", "Should create proper host address")
XCTAssertEqual(config!.user!, "ICanCreateBots")
XCTAssertEqual(config!.password!, "superSecr3t")
}
} Maybe in this case we could set public protocol JSONSerializable {
init(json: NSDictionary) throws
func jsonify() -> NSDictionary
} |
Well, we still need a way to not return an object if the JSON is corrupt or we don't have all required fields. Since Btw, why does the |
I wanted to write some tests and I was digging through the |
@pmkowal any idea which line crashes? Have you tried setting breakpoints? I wonder which line is this bad boy... 😈 |
The problem is when the |
maybe because this: try self.init(host: host, user: json.optionalStringForKey("user"), password: json.optionalStringForKey("password")) should become this: do {
try self.init(host: host, user: json.optionalStringForKey("user"), password: json.optionalStringForKey("password"))
} catch {
Log.error("Couldn't initialize server configuration: \(error)")
} ❓ |
Me and @pmkowal sat for a while on this and discussed possibilities... Seems like we're mixing too much... Okay, it's supported to call non-failable Here are my solutions:
|
Is it just me or does this work fine in |
@czechboy0 it seems very likely... I will |
Yeah, it work for It looks like a lot of work with converting everything to |
Currently some of them assert, some of them fail more gracefully. This needs to be unified with the new Swift 2 error handling system.
The text was updated successfully, but these errors were encountered: