Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mark ExceptionInterfaces throwable #2#28307

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromostrolucky:patch-18
Sep 4, 2018

Conversation

@ostrolucky
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

This has been reverted in beta of 4.1 because of lack of support in prophecy, which has been fixed since then (incl. release). Can be merged again.

References:
#26702
#27420
#27419
phpspec/prophecy#412

ping@dunglas@ciaranmcnulty@dkarlovi@Wirone@teohhanhui@stof@nicolas-grekas@ondrejmirtes

teohhanhui and Wirone reacted with thumbs up emoji
@dkarlovi
Copy link
Contributor

Can we verify the same usecase is OK with PHPUnit?

@ostrolucky
Copy link
ContributorAuthor

Seems support has been added insebastianbergmann/phpunit-mock-objects#402

dkarlovi and teohhanhui reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas added this to thenext milestoneAug 30, 2018
@fabpot
Copy link
Member

This has been reverted because it breaks BC as demonstrated by Prophecy and PHPUnit. There could be other packages/projects out there with the same issues.

@nicolas-grekas
Copy link
Member

I also think this provides little to no benefit and the BC risk is proven already.

@dkarlovi
Copy link
Contributor

dkarlovi commentedSep 4, 2018
edited
Loading

It provides benefits if you're using a static code analysis tool which notes you're trying to catch non-throwable exceptions.

I'd argue that the BC issue highlighted deeper issues in Prophecy and PHPUnit, not that it was Symfony's fault.

@fabpot
Copy link
Member

What is a non-throwable exception? Any is throwable, the interface does not add any more "power" to the exception class... or I'm missing something.

@dkarlovi
Copy link
Contributor

dkarlovi commentedSep 4, 2018
edited
Loading

If you're using the exception marker interface as intended (to catch any package's exception), you're doing something like:

try {}catch (ExceptionInterface$exception) {}

This code is marked invalid by static code analysis as the interface is not throwable, as in the fact it can be thrown at all is circumstantial.

Relying on the concrete implementation to make the interface throwable doesn't rely on the interface but the concrete implementation, making the marker interface pretty much useless.

Real example:https://github.com/dkarlovi/xezilaires/blob/60ca197333b0974d543c2e4a88f94e7d1878d3d7/src/Xezilaires/Metadata/Mapping.php#L61

Requires:
https://github.com/dkarlovi/xezilaires/blob/60ca197333b0974d543c2e4a88f94e7d1878d3d7/psalm.xml.dist#L30-L35

Wirone reacted with thumbs up emoji

@ondrejmirtes
Copy link
Contributor

I don't think it's exactly a BC break, it just showed there's a bug in Prophecy that didn't allow mocking Throwable interfaces...

teohhanhui and Wirone reacted with thumbs up emoji

@fabpot
Copy link
Member

Sorry, but unfortunately I'm too dumb to understand the issue. I will let the other @symfony/deciders team members decide.

@javiereguiluz
Copy link
Member

@ostrolucky I'm also having problems trying to understand the necessity of this change. Could you please explain very briefly (or with a small code example) what does this change allow to do that wasn't possible before? Thanks!

@ondrejmirtes
Copy link
Contributor

Basically this:https://phpstan.org/r/d90d2b30f1bd1eeb90255e92927e4fdf

You're putting something that might not be an exception into places like@throws tag orcatch block. This prevents user from making an unwanted error because he possibly wanted to write something else.

@ondrejmirtes
Copy link
Contributor

So if you intend some interfaces only to be used by exceptions, you can enforce that by extending the interface fromThrowable.

@dkarlovi
Copy link
Contributor

@dkarlovi
Copy link
Contributor

Same issue with Psalm:

https://getpsalm.org/r/c6195f9342

@stof
Copy link
Member

stof commentedSep 4, 2018

The benefit of this PR is indeed for any tool doing static analysis. So this concerns phpstan, psalm, but also IDEs (PHPStorm does not currently has such inspection in its stable version to highlight a mistake, but autocompletion incatch clauses is restricted to throwable types).

It won't make a huge difference for developers themselves (if we forget the impact on their tooling), as the only change this makes for PHP is forbidding silly mistakes (implementing something calledExceptionInterface on a class not being an exception is certainly a mistake)

Wirone reacted with thumbs up emoji

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

Choose a reason for hiding this comment

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

OK, let's do this. I don't agree with the "error" level: a "warning" would be more appropriate to me unless of course one explicitly enabled a rule to make this an error. But that's not a reason against this PR :)
About the BC break, it's true the issues were bugs actually, highlighting the fact thatThrowable is very special since the only way to implement it is by extendingExceptionorError.

Should we add a line in UPGRADING-4.2/5.0.md?

@fabpot
Copy link
Member

Ok, understood now. Thanks for the additional info.

@dkarlovi
Copy link
Contributor

It won't make a huge difference for developers themselves (if we forget the impact on their tooling)

I'd argue the "impact on their tooling" is the crucial point here: since the tooling is becoming as prevalent in a modern PHP toolbox. Looking at the pace and value the tools generate, this trend will only increase and changes like these will be just as important as any other bugfix / feature in the future.

@fabpot
Copy link
Member

Thank you@ostrolucky.

@fabpotfabpot merged commit17c3675 intosymfony:masterSep 4, 2018
fabpot added a commit that referenced this pull requestSep 4, 2018
This PR was merged into the 4.2-dev branch.Discussion----------Mark ExceptionInterfaces throwable#2| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -This has been reverted in beta of 4.1 because of lack of support in prophecy, which has been fixed since then (incl. release). Can be merged again.References:#26702#27420#27419phpspec/prophecy#412ping@dunglas@ciaranmcnulty@dkarlovi@Wirone@teohhanhui@stof@nicolas-grekas@ondrejmirtesCommits-------17c3675 Mark ExceptionInterfaces throwable
@stof
Copy link
Member

stof commentedSep 4, 2018

I'd argue the "impact on their tooling" is the crucial point here:

I totally agree on that. but I wanted to point out the other impact, as I already detailed the tooling impact previously in my comment

@nicolas-grekasnicolas-grekas removed this from thenext milestoneNov 1, 2018
@nicolas-grekasnicolas-grekas added this to the4.2 milestoneNov 1, 2018
nicolas-grekas added a commit that referenced this pull requestJul 8, 2024
…native Throwable interface (xabbuh)This PR was merged into the 7.2 branch.Discussion----------[Messenger] Let WrappedExceptionsInterface extend the native Throwable interface| Q             | A| ------------- | ---| Branch?       | 7.2| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        |Fix#57667| License       | MITWe already did that in the past for `ExceptionInterface` in#28307.Commits-------0193dcd let WrappedExceptionsInterface extend the native Throwable interface
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

8 participants

@ostrolucky@dkarlovi@fabpot@nicolas-grekas@ondrejmirtes@javiereguiluz@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp