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
Catch Clause Not Invoked #76
Comments
When I change to the following it works as expected: func verify(userId: String, withToken: String) -> Promise<Void> {
chunk1()
.then { [self] result in
chunk2()
}
.then { result in <--- 'result in' is missing from original version.
print("All done!")
}
.catch { error in
print("Got an error")
}
}
Is it possible to put a compile-time check so that the return value of previous promise must be consumed in the next? |
Real World Code func verify(userId: String, withToken: String) -> Promise<Void> {
openClient()
.then { networking in
networking.putAsync("/api/users/\(userId)/verify/", parameters: ["token": withToken])
}
} ^-- Here's the real-world culprit func verify(userId: String, withToken: String) -> Promise<Void> {
openClient()
.then { networking in
networking.putAsync("/api/users/\(userId)/verify/", parameters: ["token": withToken])
}.then { result in
print("Got result: \(result)")
}
} ^-- But like this it works as expected. Need to be careful with |
Thanks for following up, this would have been tough to figure out without that. So, if you use the void-returning |
All clear what was happening now. Perhaps some documentation is the right solution for this. My IDE (I like AppCode) always suggests to me that
. . . with an explicit return, then it would not have compiled (method signature is
But then it could also be the case that the previous step returned Void too and I still would have tripped. Helper Method To Convert Typed Promise to Void or Await For Void to Fulfillextension Promise {
func await() -> Promise<Void> {
self.then { result in }
}
} UsageRather than writing this: func verify(userId: String, withToken: String) -> Promise<Void> {
openClient()
.then { networking in
networking.putAsync("/api/users/\(userId)/verify/", parameters: ["token": withToken])
}.then { result in } <-- Which looks a bit tedious
} I created a helper that awaits the previous step in the chain and returns a Void promise like this: func verify(userId: String, withToken: String) -> Promise<Void> {
openClient()
.then { networking in
networking.putAsync("/api/users/\(userId)/verify/", parameters: ["token": withToken])
}.await() <-- Slightly better?
} Perhaps it could be a pattern when it comes to Using Promise Had a Learning CurveI found that this library is super super simple to learn, except for some potential pitfalls with Promise. Assuming others might trip in the same areas that I did, then documentation could include:
|
All done from my side, so close at will. Thanks again! |
Closing this as it seems to have been resolved. Just a quick question for you @jasperblues: if you add back the explicit return, does it also work with that? |
I've set up a somewhat complex Promise chain where the catch clause is not invoked as expected.
Here's a test-case for
Promise
(fails) and another forPromiseKit
(passes).Test case is derived from a real world app scenario that didn't work as I expected it would. Perhaps it is a user error or misunderstanding.
Failing Test:
Failing test:
PromiseKit Version
Test case:
Source for Expect/Async Function:
(Sometimes I find XCTest style expectations fussy, so I roll this one:)
The text was updated successfully, but these errors were encountered: