-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Favor LogicException for missing classes & functions #28536
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
ro0NL
commented
Sep 21, 2018
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | yes-ish |
BC breaks? | no-ish |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #28513 (comment) |
License | MIT |
Doc PR | symfony/symfony-docs#... |
@@ -100,7 +100,7 @@ public function validate($value, Constraint $constraint) | |||
|
|||
if (Email::VALIDATION_MODE_STRICT === $constraint->mode) { | |||
if (!class_exists('\Egulias\EmailValidator\EmailValidator')) { | |||
throw new RuntimeException('Strict email validation requires egulias/email-validator ~1.2|~2.0'); | |||
throw new LogicException('Strict email validation requires egulias/email-validator ~1.2|~2.0'); |
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.
That's a BC break as LogicException does not extend RuntimeException. Not sure it is worth 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.
True, but nobody can rely on this exception being thrown because a package is missing, don't you think?
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.
True, but I don't see why Logic is better than Runtime. We are using Runtime for such exceptions on the Messenger component for instance and Logic on some other components.
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.
To me, a logic exception means the code is broken (composer.json here): it's a programmer mistake. Runtime exception means some unexpected behavior was observed (e.g. broken connection, etc.)
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.
Works for me, but we should fixed this across the board then.
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.
Done.
@@ -36,7 +36,7 @@ | |||
private function lock($name = null, $blocking = false) | |||
{ | |||
if (!class_exists(SemaphoreStore::class)) { | |||
throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.'); | |||
throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); | |||
} | |||
|
|||
if (null !== $this->lock) { |
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 LogicException
below looks odd :)
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.
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.
on 2.8 actually? and unrelated to the Lock component, I was too fast :)
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.
just curious if it should be Runtime.. though Logic might be valid if the developer should call in specific order.
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.
yep, that makes sense also, asking devs to take care and pointing their mistake otherwise with LogicException
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 method should not be called twice. IMHO, this is a developer's misconception and should be a LogicException
/** | ||
* @author Roland Franssen <[email protected]> | ||
*/ | ||
class LogicException extends \LogicException implements ExceptionInterface |
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.
added to not downgrade from namespaced to root namespace exception
Thank you @ro0NL. |
…ro0NL) This PR was merged into the 4.2-dev branch. Discussion ---------- Favor LogicException for missing classes & functions | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes-ish | BC breaks? | no-ish <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28513 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- c762735 Favor LogicException for missing classes & functions
This is a follow-up of symfony#28536
…nglet) This PR was merged into the 5.4 branch. Discussion ---------- [DomCrawler] Fix Crawler::filter throw phpdoc | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | not really (phpdoc-fix) | New feature? | no | Deprecations? | no | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> The `Crawler::filter` method is calling ``` $converter = $this->createCssSelectorConverter(); ``` which is throwing a `LogicException` since #28536 So the phpdoc should be ``` `@throws` \LogicException if the CssSelector Component is not available ``` and not ``` `@throws` \RuntimeException if the CssSelector Component is not available ``` Commits ------- ae19695 Fix Crawler::filter throw phpdoc