From 5c89c66f0bdd87b4b50c401d1de22b72f4fde513 Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Fri, 7 Jul 2023 18:09:35 +0200 Subject: [PATCH] fix: remove previous exception from `UnresolvableType` Following up eaa1283, fixes an issue where cache mechanism could break when relying on serialization. --- .../InvalidConstructorReturnType.php | 4 +--- src/Type/Types/UnresolvableType.php | 19 ++++--------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/Mapper/Object/Exception/InvalidConstructorReturnType.php b/src/Mapper/Object/Exception/InvalidConstructorReturnType.php index 008c9c3b..136b66e2 100644 --- a/src/Mapper/Object/Exception/InvalidConstructorReturnType.php +++ b/src/Mapper/Object/Exception/InvalidConstructorReturnType.php @@ -17,12 +17,10 @@ public function __construct(FunctionDefinition $function) if ($returnType instanceof UnresolvableType) { $message = $returnType->message(); - $previous = $returnType->previous(); } else { $message = "Invalid return type `{$returnType->toString()}` for constructor `{$function->signature()}`, it must be a valid class name."; - $previous = null; } - parent::__construct($message, 1659446121, $previous); + parent::__construct($message, 1659446121); } } diff --git a/src/Type/Types/UnresolvableType.php b/src/Type/Types/UnresolvableType.php index c32d5553..a212e124 100644 --- a/src/Type/Types/UnresolvableType.php +++ b/src/Type/Types/UnresolvableType.php @@ -9,7 +9,6 @@ use CuyZ\Valinor\Type\Type; use CuyZ\Valinor\Utility\ValueDumper; use LogicException; -use Throwable; /** @internal */ final class UnresolvableType implements Type @@ -17,15 +16,13 @@ final class UnresolvableType implements Type public function __construct( private string $rawType, private string $message, - private ?Throwable $previous = null ) {} public static function forProperty(string $raw, string $signature, InvalidType $exception): self { return new self( $raw, - "The type `$raw` for property `$signature` could not be resolved: {$exception->getMessage()}", - $exception + "The type `$raw` for property `$signature` could not be resolved: {$exception->getMessage()}" ); } @@ -33,8 +30,7 @@ public static function forParameter(string $raw, string $signature, InvalidType { return new self( $raw, - "The type `$raw` for parameter `$signature` could not be resolved: {$exception->getMessage()}", - $exception + "The type `$raw` for parameter `$signature` could not be resolved: {$exception->getMessage()}" ); } @@ -42,8 +38,7 @@ public static function forMethodReturnType(string $raw, string $signature, Inval { return new self( $raw, - "The type `$raw` for return type of method `$signature` could not be resolved: {$exception->getMessage()}", - $exception + "The type `$raw` for return type of method `$signature` could not be resolved: {$exception->getMessage()}" ); } @@ -71,8 +66,7 @@ public static function forLocalAlias(string $raw, string $name, ClassType $type, { return new self( $raw, - "The type `$raw` for local alias `$name` of the class `{$type->className()}` could not be resolved: {$exception->getMessage()}", - $exception + "The type `$raw` for local alias `$name` of the class `{$type->className()}` could not be resolved: {$exception->getMessage()}" ); } @@ -81,11 +75,6 @@ public function message(): string return $this->message; } - public function previous(): ?Throwable - { - return $this->previous; - } - public function accepts(mixed $value): bool { throw new LogicException();