Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Sep 24, 2018
Merged

Favor LogicException for missing classes & functions #28536

merged 1 commit into from
Sep 24, 2018

Conversation

ro0NL
Copy link
Contributor

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

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@nicolas-grekas nicolas-grekas Sep 24, 2018

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

Copy link
Member

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.

Copy link
Contributor Author

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

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

Copy link
Member

Choose a reason for hiding this comment

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

you mean we should return true instead? @jderusse WDYT?
@ro0NL up for a PR on 3.4 to trigger the discussion?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

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

@ro0NL ro0NL changed the title [Validator] Leverage new LogicException Favor LogicException for missing classes & functions Sep 24, 2018
@nicolas-grekas
Copy link
Member

Thank you @ro0NL.

@nicolas-grekas nicolas-grekas merged commit c762735 into symfony:master Sep 24, 2018
nicolas-grekas added a commit that referenced this pull request Sep 24, 2018
…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
@ro0NL ro0NL deleted the validator branch September 24, 2018 08:36
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
gido added a commit to antistatique/symfony that referenced this pull request Dec 27, 2018
fancyweb added a commit that referenced this pull request Jun 5, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants