-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Exception; | ||
|
||
/** | ||
* @author Roland Franssen <franssen.roland@gmail.com> | ||
*/ | ||
class LogicException extends \LogicException implements ExceptionInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added to not downgrade from namespaced to root namespace exception |
||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Symfony\Component\Validator\Exception\RuntimeException; | ||
use Symfony\Component\Validator\Exception\LogicException; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
|
||
/** | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
$strictValidator = new \Egulias\EmailValidator\EmailValidator(); | ||
|
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.
you mean we should return true instead? @jderusse WDYT?
@ro0NL up for a PR on 3.4 to trigger the discussion?
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