-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Reject some() (and any()) if the input array contains not enough items #34
Conversation
ping @cboden @clue @WyriHaximus |
->with( | ||
$this->callback(function($exception){ | ||
return $exception instanceof RangeException && | ||
'Input array must contain at least 1 item but contains only 0 items.' === $exception->getMessage(); |
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.
The documentation seems to suggest otherwise. IMO it makes sense to reject this with a RangeException
, but we should probably also add this special case to the README.
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.
Added a note the the README (e29472f).
See remark about documentation for |
README now LGTM :) However, after further consideration, I think this should probably throw a subclass of |
Good point. I've used RangeException after discovering this bug while looking through the bluebird code and extended the SPL RangeException (which in turn extends RuntimeException). I think it would be strange to use the name RangeException and extend LogicException because this would differ from the SPL. Maybe we should use another name...any suggestions? |
@@ -515,6 +515,9 @@ will be the resolution value of the triggering item. | |||
The returned promise will only reject if *all* items in `$promisesOrValues` are | |||
rejected. The rejection value will be an array of all rejection reasons. | |||
|
|||
The returned promise will also reject with a `React\Promise\Exception\RangeException` | |||
if `$promisesOrValues` contains 0 items. |
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.
Would UnderflowException
or LengthException
, both of which extend LogicException
, make sense here?
Edit: just realised that UnderflowException
extends RuntimeException
.
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.
LengthException might be an option...
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.
Renamed to LengthException in cd6bb56.
I'm planning to add this to 3.0. |
Any objections against including this in a 2.4.0 release? |
Technically isn't this an API break? |
I think (and iirc we agreed on IRC) that this is a bug fix, because without this fix some([1, 2, 3], 4)
->then(function() {
// Never called
})
->otherwise(function() {
// Never called
}); simply does nothing. It neither calls the fulfillment nor the rejection handler. |
ah. 👍 for 2.4 then |
This fixes a bug where some() never resolves if the input array contains not enough items.