Skip to content
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

Make GuzzleException extend Throwable whereever it's available #2273

Merged
merged 1 commit into from Apr 15, 2019

Conversation

ErikBooijCB
Copy link
Contributor

Our static analyzer is giving us some issues when catching Guzzles exceptions, because they don't extend throwable and thus aren't technically catchable.

I get that we don't want to extend it by default because it would break BC with PHP5.x, but I think the proposed solution would give us the best of both worlds.

* @method string getFile()
* @method int getLine()
* @method array getTrace()
* @method string getTraceAsString()
Copy link

Choose a reason for hiding this comment

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

these annotations should not be needed anymore because the method signatures are provided by throwable

@dbu
Copy link

dbu commented Mar 19, 2019

just stumbled into this because of phpstan complaining about @throws GuzzleException when that is no throwable.

Copy link
Member

@Tobion Tobion left a comment

Choose a reason for hiding this comment

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

LGTM except the comment from @dbu
See also symfony/symfony#28307

@ErikBooijCB
Copy link
Contributor Author

@dbu @Tobion Thanks for the review and the feedback! I've updated the PR, but a unit test is now failing because of a hardcoded date in the CookieJarTest that has passed between the creation of this PR and now.

I have created a separate PR to fix that and as soon as that's merged or the issue is otherwise fixed, I'll rebase this PR to make it pass inspection.

#2278

@sagikazarmark
Copy link
Member

@ErikBooijCB thanks a lot for the PR. Can you please rebase it?

@ErikBooijCB
Copy link
Contributor Author

@sagikazarmark Absolutely, done 👍

@sagikazarmark
Copy link
Member

Thanks!

@sagikazarmark sagikazarmark merged commit e21a982 into guzzle:master Apr 15, 2019
@wirwolf
Copy link

wirwolf commented Oct 18, 2019

Hello @ErikBooijCB, i create a fork of this repo and release this marge request into the new version(6.4.0).

Namespace compatibility is 100%, and you can use my changes if you patch composer.json in your projects

  • replace "guzzlehttp/guzzle": "^6.3" to "someblackmagic/guzzle": "^6.4"
  • add "guzzlehttp/guzzle": "6.3.*" into replace block

Fork link: https://github.com/SomeBlackMagic/guzzle/

interface GuzzleException {}
use Throwable;

if (interface_exists(Throwable::class)) {
Copy link

@kronthto kronthto Nov 14, 2019

Choose a reason for hiding this comment

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

interface_exists has a second parameter autoload that defaults to true: https://www.php.net/manual/en/function.interface-exists.php

Can we explicitely pass this as false? It makes no sense imo to try autoloading a SPL class/interface, and causes issues with bad autoloader implementations that include/require everything passed to them even if such a file does not exist.

I can make a PR if needed.

Copy link
Member

Choose a reason for hiding this comment

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

pr welcome

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.

None yet

7 participants