-
Notifications
You must be signed in to change notification settings - Fork 53
Make sure we catch all exceptions #35
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
Conversation
*/ | ||
public function addFailure(RequestInterface $request, Exception $exception); | ||
public function addFailure(RequestInterface $request, \Exception $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.
Here is the BC break. Possible solution to avoid this is to introduce a new Journal interface. Could we do something better?
👍 for merging this, then look at getting throwables to work too after? |
Is there a generally accepted way for supporting both PHP 5.x and 7.x? Remove typehint or create a fallback interface, etc? |
*/ | ||
public function addFailure(RequestInterface $request, Exception $exception); | ||
public function addFailure(RequestInterface $request, \Exception $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.
This is a BC break, you cannot do that. All implementations of this interface will be broken.
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.
Here is the BC break. Possible solution to avoid this is to introduce a new Journal interface. Could we do something better?
(Same as old comment): #35 (comment)
Removing the typehint, or turning the throwable into an actual exception like symfony and laravel do. |
Odd that the StyleCI PR analysis is failing. |
I see strange SSH key added emails coming from StyleCI and that was certainly not me. |
Looking at the logs, that's because GitHub is giving us |
so, ready to merge? @Nyholm can you try to squash the commits and see if we get styleci to also analyze "pr" and not only "push"? tried to restart the build and it said its all good, but i guess that is the "push" and not the "pr". no idea how to make it rebuild "pr" |
I think the PR is ready to be merged. The PR is squashed and rebased. |
@@ -79,7 +78,7 @@ public function sendRequest(RequestInterface $request) | |||
$pluginChain = $this->createPluginChain($this->plugins, function (RequestInterface $request) { | |||
try { | |||
return new FulfilledPromise($this->client->sendRequest($request)); | |||
} catch (HttplugException $exception) { | |||
} catch (\Exception $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.
this is a BC break for custom plugins, right? before, their failure callback would accept only Http\Client\Exception, but now it could be called with \Exception. this will lead to a fatal error with parameter mismatch, where before it would be an exception that broke the chain of promises...
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.
i do think its correct to do this, but maybe we need a BC layer for this. maybe an option to the PluginClient for this new behaviour, that is off by default. version 2 can then drop the option and always catch all exceptions.
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.
i don't think this is breaking because the rejected promise class always said that it could take things that weren't http plug exceptions
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.
If one have written an function HttplugException (just like we did in HistoryPlugin) it will fail with this update. But as @GrahamCampbell says, the rejected promise class always said it would be an \Exception.
So: This is a bugfix, others may also suffer from this bug. But this is no BC break.
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.
hm, okay. but if our own classes did not adhere to what we said, we should make sure this will go into a minor version change and that the changelog is clear about it.
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.
So: write ducumentation that explains that only HTTPlug exceptions can be thrown in the plugin. And that's it?
What if a plugin cause a runtime exception? How is that handled? Should the next plugin see it?
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.
Mergy mergy!
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 problem is that the used RejectedPromise accepts any kind of exceptions, so if an exception is thrown, the rejected promise will call the reject callback with any exception. IMO there are two/three ways:
- Create a RejectedPromise, which only passes http exceptions to the callback, rethrows everything else
- When the RejectedPromise is created, make sure only HTTP exceptions are injected into the Promise (although others are possible too) and everything else is thrown immediately (this would require to modify adapter promise implementations too)
- Handle the scenario in the plugins: accept any exception and only process http ones, throw the rest (how about no?)
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.
Handle the scenario in the plugins: accept any exception and only process http ones, throw the rest (how about no?)
No, or i do not maintain this xD, it will just be a nightmare to handle (also accepting this, say that we expect people not respecting httplug async standard... )
Create a RejectedPromise, which only passes http exceptions to the callback, rethrows everything else
When the RejectedPromise is created, make sure only HTTP exceptions are injected into the Promise (although others are possible too) and everything else is thrown immediately (this would require to modify adapter promise implementations too)
👍 and we must do the same for the FulfilledPromise, as actually it's accept anything, where we should only allow ResponseInterface
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 PR is here php-http/httplug#116
👍 for merging |
👍 |
Should we close this as well since #42 has been merged ? |
Correct. Thank you |
yesnoyesWhat's in this PR?
I widening the type hints to catch all exceptions.