-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Enforce throwables/exceptions as rejection reasons #93
Conversation
66ce56b
to
411a415
Compare
|
||
namespace React\Promise\Exception; | ||
|
||
class CompositeException extends \Exception |
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.
How about MultiReasonException
?
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.
No objections to either class name, but the use of this class appears a bit unclear. Does it make sense to add documentation for this class and/or mark this class a @internal
?
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 documentation in 07b7afd. I think it makes sense to keep it public API as it might be useful for custom collection functions.
I like the idea of only accepting |
@clue I thought about that myself, but if only ini_set('assert.exception', 1);
$promise = new \React\Promise\Promise(function() {
assert(1 === 0);
});
$nextPromise = $promise->otherwise(function($e) {
handle($e);
// $e is AssertionError and can't be passed to reject()
return \React\Promise\reject($e);
}); A solution would be to just rethrow, but that needs to be documented (and the documentation read by the user). $nextPromise = $promise->otherwise(function($e) {
handle($e);
throw $e;
}); |
@clue Why would one want to not support |
Explicitly not supporting |
isn't the point of this PR to be "not longer possible to reject a promise without a reason |
I'm 👍 on getting this in and didn't mean to question whether supporting |
@clue In fact, |
Ping @clue |
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.
Good catch! I think this feature and corresponding BC break makes perfect sense 👍
I have a couple of questions regarding the new custom exception classes, otherwise LGTM 👍
|
||
namespace React\Promise\Exception; | ||
|
||
class CompositeException extends \Exception |
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.
No objections to either class name, but the use of this class appears a bit unclear. Does it make sense to add documentation for this class and/or mark this class a @internal
?
a2809c2
to
df0976e
Compare
@jsor Would you be up for standardizing the |
I've added [WIP] to the PR title. We still need to figure out how we can keep interoperabilty with other promise implementations which allow rejecting with non-exception reasons. new Promise(function($resolve, $reject) use ($foreignPromise) {
$foreignPromise->then($resolve, $reject);
}); This would now reject One solution would be to wrap the reason in a |
Do we have a relevant use case where this happens? |
@clue Lines 11 to 21 in c1aad8e
|
@jsor It's my understanding that if a foreign promise rejects with something that is not an As far as I can tell, the ecosystem of foreign promises also seem to rely on Are you seeing anything that is missing here and/or is commonly used in other projects? |
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.
LGTM !
ping @clue |
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.
Changes LGTM! 🎉
One thing: Once this is in, I would like to look into enforcing a |
Well either of us can do that, but I'd like to get an PR out A.S.A.P. adding exactly that and raising minimum PHP version to 7.0 |
@WyriHaximus Go for it! |
@clue 🎉 ! |
Because rejections are the promise counter parts of throwing an exception, throwables/exceptions should be enforced as rejection reasons.
Also, ReactPHP has always used exceptions as rejection reasons throughout it's components.
Closes #46