Skip to content

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

Closed
wants to merge 1 commit into from
Closed

Make sure we catch all exceptions #35

wants to merge 1 commit into from

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Jul 31, 2016

Q A
Bug fix? yes
New feature? yes
BC breaks? yes no yes
Deprecations? no
Related tickets fixes #34, related to #33
Documentation
License MIT

What's in this PR?

I widening the type hints to catch all exceptions.

*/
public function addFailure(RequestInterface $request, Exception $exception);
public function addFailure(RequestInterface $request, \Exception $exception);
Copy link
Member Author

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?

@GrahamCampbell
Copy link
Contributor

👍 for merging this, then look at getting throwables to work too after?

@sagikazarmark
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

@Nyholm Nyholm Aug 1, 2016

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)

@GrahamCampbell
Copy link
Contributor

Is there a generally accepted way for supporting both PHP 5.x and 7.x? Remove typehint or create a fallback interface, etc?

Removing the typehint, or turning the throwable into an actual exception like symfony and laravel do.

@GrahamCampbell
Copy link
Contributor

Odd that the StyleCI PR analysis is failing.

@sagikazarmark
Copy link
Member

I see strange SSH key added emails coming from StyleCI and that was certainly not me.

@GrahamCampbell
Copy link
Contributor

Looking at the logs, that's because GitHub is giving us Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. when we try to analyze the PR, so the system tries to repair the deploy key.

@dbu
Copy link
Contributor

dbu commented Aug 2, 2016

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"

@Nyholm
Copy link
Member Author

Nyholm commented Aug 2, 2016

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) {
Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mergy mergy! :trollface:

Copy link
Member

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?)

Copy link
Member

@joelwurtz joelwurtz Aug 3, 2016

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

Copy link
Member

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

@GrahamCampbell
Copy link
Contributor

👍 for merging

@cursedcoder
Copy link

👍

@joelwurtz
Copy link
Member

Should we close this as well since #42 has been merged ?

@Nyholm
Copy link
Member Author

Nyholm commented Sep 1, 2016

Correct. Thank you

@Nyholm Nyholm closed this Sep 1, 2016
@Nyholm Nyholm deleted the issue-34 branch September 1, 2016 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clear exception usage in Plugins
6 participants