Comments (5)
Looks cool :)
Do you propose to have it alongside the existing catch
operator as an overload?
I'm afraid it will interfere with the existing Error-only catch
, and the complier would silently pick one overload over another, or complain unless you clearly state the error type.
Anyhow, pull requests are more than welcome!
from promises.
@gloooooooomy let's close this issue for now, but don't hesitate to follow up if you have any ideas on how to deal with the current compiler limitations.
from promises.
@shoumikhin sorry for reply too late. :(
now i know exactly what you concerned. and I'll check if there's another way to avoid.
from promises.
Yes, i proposed catch operator as an overloaded function.
because compiler could infers the generic type only when state the error type.
.catch { (error: MyError) in
// compiler picks generic catch operator.
}
.catch { (error: Error) in
// compiler picks default catch. because generic type does not supports protocol.
}
.catch { error in
// same as "error: Error"
}
also i made a pull requests, please review :)
from promises.
@gloooooooomy thank you, I love your proposal!
Just have a concern with the case like the following:
enum CustomError: Error { case test }
Promise<Void> {
throw Test.Error.code42
}.then { _ in
XCTFail()
}.catch { error in
XCTAssertTrue(error == CustomError.test) // Never executed.
}
I imagine, it's expected that the catch
above to be executed w/o specifying the error type explicitly, since it must catch all Error
s. Unfortunately, it's not, because the compiler translates that one-liner catch
as your generic version and derives the type based on the condition in the test assert. I.e. it thinks the catch
generic type must be CustomError
. But Test.Error
is thrown, in fact. So that catch
is never executed, since types don't match. To fix that behavior, one should either specify the expected error type explicitly as (error: Error) in
(which is not always convenient and can be omitted by mistake), or write more than one line of code inside the catch
closure to force the compiler to pick a more suitable non-generic catch
overload (and that is potentially error-prone, because the clients may not be aware about such subtle implications).
Ideally, we'd want something like default generic arguments be implemented in Swift to have only one version of catch
, and actually make it generic, as you've proposed.
What do you think?
from promises.
Related Issues (20)
- Sometimes Post Request Timeout HOT 6
- FBLPromises crashing HOT 2
- Question. Is it possible to change the delay time between retrys?
- Bug in iOS 16 DevBeta1 HOT 13
- Extremely slow compile time of Objective-C files
- Contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
- Objective-C Promises crashes in SwiftUI previews HOT 2
- ios 16 strings convertible to NSError HOT 1
- FBLPromises fails to load building macos flutter app HOT 2
- 'NSInvalidArgumentException', reason: '-[FBLPromise HTTPBody]: unrecognized selector sent to instance HOT 1
- Confused when retry a Promise variable
- type(of: value) is NSError.Type HOT 1
- Bitcode Issue on Xcode 13 when disable it. HOT 1
- Question regarding implementation HOT 3
- Ignore a certain Error and terminate Promise HOT 5
- Please release a new version of promises that includes latest changes for Firebase HOT 4
- Builds including PromisesSwift failing on CI
- Build fails for macOS with Xcode 14.3
- Create releases for new versions HOT 1
- The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.0.99.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promises.