fix(state): use exception message for user-facing violation when available#7894
Conversation
…lable When a NotNormalizableValueException has canUseMessageForUser() = true, use its message directly as the constraint violation message instead of the generic Type constraint message. This fixes issues with Symfony 8.x where expectedTypes can be null/empty, producing broken messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…expectedTypes Simulates the behavior from symfony/serializer PR #62574 where an invalid enum value produces an exception with expectedTypes=null and a user-friendly message listing valid values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ymfony compat - Sort ValidationException import alphabetically in DeserializeProviderTest - Update ValidationTest to expect exception message when canUseMessageForUser() is true - Use positional params for NotNormalizableValueException ctor (lowest Symfony compat) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… violations These violations have canUseMessageForUser()=true, so the new behavior uses the exception message directly instead of the generic type message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The extended NotNormalizableValueException constructor (with path and useMessageForUser params) doesn't exist on lowest Symfony versions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
thanks! |
|
The whole point of this IIRC was to use explicitly the same message that the validator would return. Now it's a BC break and will need to fix our testsuite |
|
its not released yet we can rollback, I thought that the WDYT @vincentchalamon ? It looks like this is fixing a bug for 8.1 and shouldn't impact actual behavior no @norkunas can you give more details? maybe we're missing a regression test? |
| $violationBaz = $findViolation('baz'); | ||
| $this->assertNotNull($violationBaz, 'Violation for "baz" not found.'); | ||
| $this->assertSame('This value should be of type string.', $violationBaz['message']); | ||
| $this->assertSame('Failed to create object because the class misses the "baz" property.', $violationBaz['message']); |
There was a problem hiding this comment.
these should not change to preserve BC I guess
There was a problem hiding this comment.
yup, this is what i was refering to.
There was a problem hiding this comment.
though the new messages are way clearer... in 8.1 this breaks and we get "This value should be of type ." not sure how to fix this properly. Isn't that not covered by BC anyways (https://symfony.com/doc/current/contributing/code/bc.html#using-our-translations) ?
When a NotNormalizableValueException has canUseMessageForUser() = true, use its message directly as the constraint violation message instead of the generic Type constraint message. This fixes issues with Symfony 8.x where expectedTypes can be null/empty, producing broken messages.