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

[FrameworkBundle] Added friendly exception when constraint validator class does not exist#19601

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

Closed

Conversation

@yceruto
Copy link
Member

@ycerutoyceruto commentedAug 12, 2016
edited
Loading

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

Currently when mistakenly we type aCustom Constraint Validator class or the "alias name" fromvalidator service (which would occurs frequently for newcomers) is shownClassNotFoundException:

Attempted to load class "alias_name" from namespace "Symfony\Component\Validator".
Did you forget a "use" statement for another namespace?
500 Internal Server Error - ClassNotFoundException

This PR tries to improve the error message when this happen.

But I'm not sure about the exception class used (InvalidArgumentException) : ?

The text message more convenient from this little mistake: ?

  • This mistake happen for two reason: FQCN or alias name supplied by constraint not found.
  • The constraint validator service was declared incorrectly (missing alias)
  • Perhaps some hint how the developer should resolve the mistake.

Maybe some documentation core member would help me ?

ogizanagi reacted with thumbs up emoji
@ycerutoyceruto changed the titleAdded friendly exception when constraint validator class does not exist[FrameworkBundle] Added friendly exception when constraint validator class does not existAug 12, 2016
@ycerutoycerutoforce-pushed thevalidator-class-exception branch 2 times, most recently from234116b to58a2f49CompareAugust 12, 2016 13:24

if (!isset($this->validators[$name])) {
if (!class_exists($name)) {
thrownewInvalidArgumentException(sprintf('Constraint validator class "%s" does not exist.',$name));
Copy link
MemberAuthor

@ycerutoycerutoAug 12, 2016
edited
Loading

Choose a reason for hiding this comment

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

It's the correct exception class in this case? you could improve the text message? see the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a simpleValidatorException as used in theValidatorBuilder ?

yceruto reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thanks, agree with you.

Now, what do you think about the message ? Should be a little bit friendly ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's friendly enough, but perhaps you can mention thevalidatedBy method.

yceruto reacted with thumbs up emoji
@ycerutoycerutoforce-pushed thevalidator-class-exception branch 3 times, most recently fromd923926 tof070965CompareAugust 16, 2016 14:39
@yceruto
Copy link
MemberAuthor

Updated! both exception class and text message have been improved.@ogizanagi thanks one more time.

@ycerutoycerutoforce-pushed thevalidator-class-exception branch 2 times, most recently fromd444bed to80dda7cCompareAugust 16, 2016 15:02

if (!isset($this->validators[$name])) {
if (!class_exists($name)) {
thrownewValidatorException(sprintf(

Choose a reason for hiding this comment

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

on one line please

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed 👍

@ycerutoycerutoforce-pushed thevalidator-class-exception branch from80dda7c to0142a83CompareAugust 23, 2016 12:38

if (!isset($this->validators[$name])) {
if (!class_exists($name)) {
thrownewValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s"',$name,get_class($constraint)));
Copy link
Member

Choose a reason for hiding this comment

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

Missing dot at the end of the exception message.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed!

@fabpot
Copy link
Member

As it already throws an exception, I think this should be merged in 2.7. ping @symfony/deciders

ogizanagi reacted with thumbs up emoji

@ycerutoycerutoforce-pushed thevalidator-class-exception branch from0142a83 to18cd50cCompareAugust 23, 2016 19:28
@yceruto
Copy link
MemberAuthor

yceruto commentedAug 23, 2016
edited
Loading

@fabpot I should create a separate PR for 2.7 branch?

@HeahDude
Copy link
Contributor

👍 as a bug fix

1 similar comment
@dunglas
Copy link
Member

👍 as a bug fix

@fabpot
Copy link
Member

Thank you@yceruto.

fabpot added a commit that referenced this pull requestAug 24, 2016
… validator class does not exist (yceruto)This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes#19601).Discussion----------[FrameworkBundle] Added friendly exception when constraint validator class does not exist| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Currently when mistakenly we type a [Custom Constraint Validator class](http://symfony.com/doc/current/validation/custom_constraint.html#creating-the-validator-itself) or the "alias name" from [validator service](http://symfony.com/doc/current/validation/custom_constraint.html#constraint-validators-with-dependencies)  (which would occurs frequently for newcomers) is shown `ClassNotFoundException`:> Attempted to load class "alias_name" from namespace "Symfony\Component\Validator".Did you forget a "use" statement for another namespace?500 Internal Server Error - ClassNotFoundException**This PR tries to improve the error message when this happen.**But I'm not sure about the exception class used ([`InvalidArgumentException`](https://github.com/yceruto/symfony/blob/master/src/Symfony/Component/Validator/Exception/InvalidArgumentException.php)) : ?*  [`ConstraintDefinitionException`](https://github.com/yceruto/symfony/blob/master/src/Symfony/Component/Validator/Exception/ConstraintDefinitionException.php) would be another option, because the source of the error comes from the custom [`Constraint`](https://github.com/yceruto/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php#L68) definition.The text message more convenient from this little mistake: ?* This mistake happen for two reason: FQCN or alias name supplied by constraint not found.* The constraint validator service was declared incorrectly (missing alias)* Perhaps some hint how the developer should resolve the mistake.Maybe some documentation core member would help me ?Commits-------b66ea5e added friendly exception when constraint validator does not exist or it is not enabled
@fabpot
Copy link
Member

@yceruto FYI, we are able to merge PR on a different branch without you having to create a new PR :)

yceruto reacted with thumbs up emoji

@fabpotfabpot closed thisAug 24, 2016
@ycerutoyceruto deleted the validator-class-exception branchAugust 24, 2016 12:11
This was referencedSep 2, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@yceruto@fabpot@HeahDude@dunglas@nicolas-grekas@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp