From 6edea0f0807bc3cc698865f9ae30d4200d644001 Mon Sep 17 00:00:00 2001 From: Dany Maillard Date: Fri, 10 Dec 2021 19:31:06 +0100 Subject: [PATCH] Keep the previous exception when rethrowing parse errors --- src/Normalizer/DurationNormalizer.php | 2 +- src/Normalizer/InstantNormalizer.php | 2 +- src/Normalizer/LocalDateIntervalNormalizer.php | 2 +- src/Normalizer/LocalDateNormalizer.php | 2 +- src/Normalizer/LocalDateTimeIntervalNormalizer.php | 2 +- src/Normalizer/LocalDateTimeNormalizer.php | 2 +- src/Normalizer/LocalTimeIntervalNormalizer.php | 2 +- src/Normalizer/LocalTimeNormalizer.php | 2 +- src/Normalizer/MonthDayNormalizer.php | 2 +- src/Normalizer/YearMonthNormalizer.php | 2 +- src/Normalizer/YearNormalizer.php | 2 +- src/Normalizer/YearWeekNormalizer.php | 6 +++--- src/Normalizer/ZonedDateTimeNormalizer.php | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Normalizer/DurationNormalizer.php b/src/Normalizer/DurationNormalizer.php index e26a4e6..722811b 100644 --- a/src/Normalizer/DurationNormalizer.php +++ b/src/Normalizer/DurationNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return Duration::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/InstantNormalizer.php b/src/Normalizer/InstantNormalizer.php index 733adf2..00e19a9 100644 --- a/src/Normalizer/InstantNormalizer.php +++ b/src/Normalizer/InstantNormalizer.php @@ -31,7 +31,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return ZonedDateTime::parse($data)->getInstant(); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalDateIntervalNormalizer.php b/src/Normalizer/LocalDateIntervalNormalizer.php index 2fe0bc8..90a1e78 100644 --- a/src/Normalizer/LocalDateIntervalNormalizer.php +++ b/src/Normalizer/LocalDateIntervalNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalDateInterval::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalDateNormalizer.php b/src/Normalizer/LocalDateNormalizer.php index 6f1f7da..2251c45 100644 --- a/src/Normalizer/LocalDateNormalizer.php +++ b/src/Normalizer/LocalDateNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalDate::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalDateTimeIntervalNormalizer.php b/src/Normalizer/LocalDateTimeIntervalNormalizer.php index 5db82c2..f7094db 100644 --- a/src/Normalizer/LocalDateTimeIntervalNormalizer.php +++ b/src/Normalizer/LocalDateTimeIntervalNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalDateTimeInterval::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalDateTimeNormalizer.php b/src/Normalizer/LocalDateTimeNormalizer.php index c2906a4..e71affe 100644 --- a/src/Normalizer/LocalDateTimeNormalizer.php +++ b/src/Normalizer/LocalDateTimeNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalDateTime::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalTimeIntervalNormalizer.php b/src/Normalizer/LocalTimeIntervalNormalizer.php index 9db055e..c92476a 100644 --- a/src/Normalizer/LocalTimeIntervalNormalizer.php +++ b/src/Normalizer/LocalTimeIntervalNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalTimeInterval::parse($data); } catch (Throwable $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/LocalTimeNormalizer.php b/src/Normalizer/LocalTimeNormalizer.php index c097390..1580a1a 100644 --- a/src/Normalizer/LocalTimeNormalizer.php +++ b/src/Normalizer/LocalTimeNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return LocalTime::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/MonthDayNormalizer.php b/src/Normalizer/MonthDayNormalizer.php index d77069f..b898c72 100644 --- a/src/Normalizer/MonthDayNormalizer.php +++ b/src/Normalizer/MonthDayNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return MonthDay::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/YearMonthNormalizer.php b/src/Normalizer/YearMonthNormalizer.php index 11d0758..1698adc 100644 --- a/src/Normalizer/YearMonthNormalizer.php +++ b/src/Normalizer/YearMonthNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return YearMonth::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/YearNormalizer.php b/src/Normalizer/YearNormalizer.php index 439c3cd..23e6e91 100644 --- a/src/Normalizer/YearNormalizer.php +++ b/src/Normalizer/YearNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return Year::of((int) $data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } } diff --git a/src/Normalizer/YearWeekNormalizer.php b/src/Normalizer/YearWeekNormalizer.php index 68c4c67..888ed2c 100644 --- a/src/Normalizer/YearWeekNormalizer.php +++ b/src/Normalizer/YearWeekNormalizer.php @@ -32,9 +32,9 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return YearWeek::of(...map((array) explode('-W', (string) $data, 2), static fn (string $part): int => (int) $part)); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); - } catch (Throwable) { - throw new NotNormalizableValueException('Invalid format for year week.'); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); + } catch (Throwable $e) { + throw new NotNormalizableValueException('Invalid format for year week.', 0, $e); } } diff --git a/src/Normalizer/ZonedDateTimeNormalizer.php b/src/Normalizer/ZonedDateTimeNormalizer.php index 45c006c..6e11033 100644 --- a/src/Normalizer/ZonedDateTimeNormalizer.php +++ b/src/Normalizer/ZonedDateTimeNormalizer.php @@ -30,7 +30,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a try { return ZonedDateTime::parse($data); } catch (DateTimeException $e) { - throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type)); + throw new NotNormalizableValueException(sprintf('%s (%s)', $e->getMessage(), $type), 0, $e); } }