-
Notifications
You must be signed in to change notification settings - Fork 102
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
Errors thrown in an Async#map don't always become Rejected #387
Comments
@flintinatux Sorry it took so long to get back to you sir. I was going back through my notes and it looks like we did this by design. It has to do with If you need to trap errors, may I suggest moving from Please let me know if you can think of a good argument against its current implementation that can also make the maths balance. |
Thanks for taking a look at, @evilsoft. I understand the maths, so I think that's fine. The trouble is that the behavior doesn't match when the |
@flintinatux Oh. I totes agree with that. The way I justified that before, is that it we a Nat Transform from
I have learn to trust the ol' @flintinatux gut, so do any of those options sparkle for you? Do you happen to have another suggestion? |
The way it feels as a consumer of the library is that if I've got an Which is a bummer, because in my head an |
So are you cool with this resolution or is there something more you think we should explore. Funny thing the two things that make a Promise, not a
These (2) things are some of the motivating reason that @puffnfresh create
quoted from: this discussion and thus Fantasy Land was born!! |
Maybe it's because I've spent most of my coding career in Javascript, but I find the development of the language fascinating/totally-cray. New features either drown in higher expectations than the original motivation (like Promises, meant to provide better async error-handling than callback hell, but not good enough because they aren't perfect monads), or they end up converted by third-party libraries into uses that don't even come close to the original spec (like react/babel/webpack's usage of I could continue, but back on point: I'll almost always vote for consistency and fewer surprises. I submitted this issue because I got surprised and - as a result - confused. Whatever we can do to follow the maths rules AND not be unexpected, that will be a win in my book. |
Functor laws require this to be the implementation, if you follow the rules, it can't be unexpected behaviour. Also, we shouldn't use exceptions, ever. |
There's no such thing as "perfect" monads. Monad has a definition so something either is, or isn't. Promises could have been monadic, and they would have been far more useful. I believe this even more, 6 years later. |
My apologies. I took the bait and wandered into opinion territory, and now we're off topic. I'll wander back. The issue at hand is this:
I find this mismatch in behaviour to be unexpected. Am I incorrect in feeling this way? If this should be expected behaviour, I guess at the very least I would want it documented to try and avoid surprises. |
@flintinatux So the reason it has to work this way is because in the Category of (gotta squint a little and ignore some bottoms) Javascript Types and Functions, Promises were created with this Error Handling in place. In order to provide a valid Functor, it MUST behave the same way in its source category when we get Async involved. The issue is that we do not know the behavior when dealing with a Promise at the head or "chain"-ed in. Sometime it will throw, sometime it will not, depending on if So the user of a Another option would be to somehow (don't know how yet, maybe with how the type is logged) signal to the user that a promise is in the mix. But no matter where we go, I agree to start we need good documentation around the what and why of this behavior. |
Ok. If this behavior is correct, and should be expected, then I think the appropriate action is just to document it. Documentation is foremost about education, and the As for me, I'll go ahead and start bending the spoon in my own mind, and change my expectations. Thanks again for helping me understand. |
Should not have closed, docs work is still not done |
Describe the bug
If an error is thrown in an
Async#map
, it doesn't always become aRejected
.To Reproduce
Expected behavior
I would expect an object shaped like
{ err }
to be logged toconsole.error
, but instead the error is thrown and logged by itself, and neither of the forked functions are called.Additional context
If you wrap a Promise instead, it works as expected:
The text was updated successfully, but these errors were encountered: