Skip to content

[HttpKernel] Fix RequestPayloadValueResolver handling error with no ExpectedTypes #52131

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
Jan 30, 2024

Conversation

Jeroeny
Copy link
Contributor

@Jeroeny Jeroeny commented Oct 18, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
License MIT

The NotNormalizableValueException errors in PartialDenormalizationException->getErrors() have a ->getExpectedTypes() method that returns array|null. The RequestPayloadValueResolver assumes this is always an array.

When the returned value is null, an Exception is thrown with implode(): Argument #1 ($pieces) must be of type array, string given.

Also the exception message in case of an empty array was: This value should be of type ..

#SymfonyHackday

@chalasr
Copy link
Member

chalasr commented Jan 29, 2024

Could you please rebase?

@nicolas-grekas
Copy link
Member

Thank you @Jeroeny.

@nicolas-grekas nicolas-grekas merged commit 78f82b9 into symfony:6.3 Jan 30, 2024
@@ -108,11 +108,15 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
} catch (PartialDenormalizationException $e) {
$trans = $this->translator ? $this->translator->trans(...) : fn ($m, $p) => strtr($m, $p);
foreach ($e->getErrors() as $error) {
$parameters = ['{{ type }}' => implode('|', $error->getExpectedTypes())];
$parameters = [];
$template = 'This value was of an unexpected type.';
Copy link
Member

Choose a reason for hiding this comment

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

Note that this message is not in translation maps. Dunno if it matters. Does it?

This was referenced Jan 30, 2024
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