Skip to content
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

Keep the previous exception when rethrowing parse errors #3

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Normalizer/DurationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/InstantNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalDateIntervalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalDateNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalDateTimeIntervalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalDateTimeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalTimeIntervalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/LocalTimeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/MonthDayNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/YearMonthNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/YearNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Normalizer/YearWeekNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizer/ZonedDateTimeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down