<p dir="auto">It would be nice in my opinion to be able from the validator errors to know what kind of assertion has been done to generate that error.</p>
<p dir="auto">For example, we've inserted to the User entity an email field with value 'somebadvalue'. If we're displaying a form that's ok since it automatically shows the error in the right place and the user knows about it.</p>
<p dir="auto">But if we manually validate the User entity, using the validation service, we've just a bunch of errors that doesn't let us know which kind of assertion has been done in an unique way.</p>
<p dir="auto">We can just match the message but it's easy to be wrong checking only that. It would be nice to add the assertion object or at least the assertion class name, what you guys think?</p>
<p dir="auto">Following my <a href="http://stackoverflow.com/q/15206637/744147" rel="nofollow">(unanswered) question at StackOverflow</a> I'm reporting this as a bug, as no one seems to know the answer.</p>
<p dir="auto">Currently there's no way that I can see to populate the <code class="notranslate">code</code> property for the <code class="notranslate">ConstraintViolation</code> class, as it is not defined in the <code class="notranslate">Constraint</code> class. But as I see, it goes farther than that, as all the validators just ignore the parameters for the <code class="notranslate">addViolation</code> method, making it impossible for simple asserts to define a code for the violation.</p>
<p dir="auto">What I expect it to allow is the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
 * @Assert\NotBlank(code=400)
 * @Assert\Email(code=401)
 */
protected $email;"><pre class="notranslate"><code class="notranslate">/**
 * @Assert\NotBlank(code=400)
 * @Assert\Email(code=401)
 */
protected $email;
</code></pre></div>
<p dir="auto">Problem is, the current validators call <code class="notranslate">addViolations</code> without setting the 5th argument (<code class="notranslate">code</code>). Plus, the <code class="notranslate">Constraint</code> class doesn't implement such a <code class="notranslate">code</code> property as mentioned.</p>
<p dir="auto">If this is indeed considered a bug, I would like to send a PR with a patch, provided that this is the way that it should be working.If it's not, some directions would be amazing!</p>