Skip to content

Make sure we catch all exceptions - #35

Closed
Nyholm wants to merge 1 commit into
masterfrom
issue-34
Closed

Nyholm wants to merge 1 commit into
masterfrom
issue-34

Conversation

@Nyholm

@Nyholm Nyholm commented Jul 31, 2016 •

Copy link
Copy Markdown
Member
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.

Comment thread src/Plugin/Journal.php Outdated
* @param \Exception $exception Exception returned by the call
*/
public function addFailure(RequestInterface $request, Exception $exception);
public function addFailure(RequestInterface $request, \Exception $exception);

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@sagikazarmark

Copy link
Copy Markdown
Member

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

Comment thread src/Plugin/Journal.php Outdated
* @param \Exception $exception Exception returned by the call
*/
public function addFailure(RequestInterface $request, Exception $exception);
public function addFailure(RequestInterface $request, \Exception $exception);

Copy link
Copy Markdown
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.

@Nyholm Nyholm Aug 1, 2016 •

Copy link
Copy Markdown
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?

(Same as old comment): #35 (comment)

@GrahamCampbell

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Odd that the StyleCI PR analysis is failing.

@sagikazarmark

Copy link
Copy Markdown
Member

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

@GrahamCampbell

Copy link
Copy Markdown
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

dbu commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

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

Nyholm commented Aug 2, 2016

Copy link
Copy Markdown
Member Author

I think the PR is ready to be merged.

The PR is squashed and rebased.

Comment thread src/PluginClient.php
try {
return new FulfilledPromise($this->client->sendRequest($request));
} catch (HttplugException $exception) {
} catch (\Exception $exception) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?)

@joelwurtz joelwurtz Aug 3, 2016 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Contributor

👍 for merging

@cursedcoder

Copy link
Copy Markdown

👍

@joelwurtz

Copy link
Copy Markdown
Member

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

@Nyholm

Nyholm commented Sep 1, 2016

Copy link
Copy Markdown
Member Author

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