Skip to content

Commit b97bc53

Browse files
committed
[Serializer] Improve UidNormalizer denormalize error message
1 parent 9870e7e commit b97bc53

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ public function denormalize($data, string $type, string $format = null, array $c
7171
{
7272
try {
7373
return AbstractUid::class !== $type ? $type::fromString($data) : Uuid::fromString($data);
74-
} catch (\InvalidArgumentException $exception) {
75-
throw NotNormalizableValueException::createForUnexpectedDataType('The data is not a valid UUID string representation.', $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
76-
} catch (\TypeError $exception) {
77-
throw NotNormalizableValueException::createForUnexpectedDataType('The data is not a valid UUID string representation.', $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
74+
} catch (\InvalidArgumentException|\TypeError $exception) {
75+
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
7876
} catch (\Error $e) {
7977
if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) {
8078
return $this->denormalize($data, AbstractUid::class, $format, $context);

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ public function testCollectDenormalizationErrors()
884884
],
885885
'path' => 'uuid',
886886
'useMessageForUser' => true,
887-
'message' => 'The data is not a valid UUID string representation.',
887+
'message' => 'The data is not a valid "Symfony\Component\Uid\Uuid" string representation.',
888888
],
889889
[
890890
'currentType' => 'null',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy