Skip to content

Commit

Permalink
Improve exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 17, 2023
1 parent 5328cfa commit cb073b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Serializer/CastToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function __construct(
DateTimeInterface::class !== $class && !Type::Mixed->equals($type) => $class,
null === $dateClass => DateTimeImmutable::class,
class_exists($dateClass) && (new ReflectionClass($dateClass))->implementsInterface(DateTimeInterface::class) => $dateClass,
default => throw new MappingFailed('`'.$reflectionProperty->getName().'` type is `mixed`; the specify `DateTimeInterface` class via the `$dateClass` argument is invalid or could not be found.'),
default => throw new MappingFailed('`'.$reflectionProperty->getName().'` type is `mixed` and the specified class via the `$dateClass` argument is invalid or could not be found.'),
};

try {
$this->timezone = is_string($timezone) ? new DateTimeZone($timezone) : $timezone;
$this->default = (null !== $default) ? $this->cast($default) : $default;
} catch (Throwable $exception) {
throw new MappingFailed(message: 'The configuration option for `'.self::class.'` are invalid.', previous: $exception);
throw new MappingFailed('The `timezone` and/or `format` options used for `'.self::class.'` are invalud.', 0, $exception);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/CastToEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
try {
$this->default = (null !== $default) ? $this->cast($default) : $default;
} catch (TypeCastingFailed $exception) {
throw new MappingFailed(message:'The configuration option for `'.self::class.'` are invalid.', previous: $exception);
throw new MappingFailed(message:'The `default` option is invalid.', previous: $exception);
}
}

Expand Down

0 comments on commit cb073b6

Please sign in to comment.