From 7d2e44971548957398351d8ad695d18c28e7bd2c Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 18 Oct 2018 08:31:31 +0200 Subject: [PATCH] Remove try/catch for error/exception thrown on type loading --- src/Resolver/TypeResolver.php | 37 ++++-------------------- tests/Functional/Security/AccessTest.php | 4 +-- tests/Resolver/TypeResolverTest.php | 12 -------- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/src/Resolver/TypeResolver.php b/src/Resolver/TypeResolver.php index f11a26b65..ee8d758cd 100644 --- a/src/Resolver/TypeResolver.php +++ b/src/Resolver/TypeResolver.php @@ -38,21 +38,14 @@ private function string2Type($alias) private function baseType($alias) { - try { - $type = $this->getSolution($alias); - } catch (\Error $error) { - throw self::createTypeLoadingException($alias, $error); - } catch (\Exception $exception) { - throw self::createTypeLoadingException($alias, $exception); + $type = $this->getSolution($alias); + if (null === $type) { + throw new UnresolvableException( + \sprintf('Could not found type with alias "%s". Do you forget to define it?', $alias) + ); } - if (null !== $type) { - return $type; - } - - throw new UnresolvableException( - \sprintf('Unknown type with alias "%s" (verified service tag)', $alias) - ); + return $type; } private function wrapTypeIfNeeded($alias) @@ -85,24 +78,6 @@ private function hasNeedListOfWrapper($alias) return false; } - /** - * @param string $alias - * @param \Exception $errorOrException - * - * @return \RuntimeException - */ - private static function createTypeLoadingException($alias, $errorOrException) - { - return new \RuntimeException( - \sprintf( - 'Type class for alias %s could not be load. If you are using your own classLoader verify the path and the namespace please.', - \json_encode($alias) - ), - 0, - $errorOrException - ); - } - protected function supportedSolutionClass() { return Type::class; diff --git a/tests/Functional/Security/AccessTest.php b/tests/Functional/Security/AccessTest.php index d5a2fca85..f484d18cc 100644 --- a/tests/Functional/Security/AccessTest.php +++ b/tests/Functional/Security/AccessTest.php @@ -56,8 +56,8 @@ public function setUp() } /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Type class for alias "RootQuery" could not be load. If you are using your own classLoader verify the path and the namespace please. + * @expectedException \Error + * @expectedExceptionMessage Class 'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType' not found * @requires PHP 7 */ public function testCustomClassLoaderNotRegister() diff --git a/tests/Resolver/TypeResolverTest.php b/tests/Resolver/TypeResolverTest.php index 575273948..476730bc5 100644 --- a/tests/Resolver/TypeResolverTest.php +++ b/tests/Resolver/TypeResolverTest.php @@ -27,18 +27,6 @@ public function createObjectType(array $config) return new ObjectType($config); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Type class for alias "type" could not be load. If you are using your own classLoader verify the path and the namespace please. - */ - public function testErrorLoadingType() - { - $this->resolver->addSolution('type', function () { - throw new \Exception('Could not load type.'); - }); - $this->resolver->resolve('type'); - } - /** * @expectedException \Overblog\GraphQLBundle\Resolver\UnsupportedResolverException * @expectedExceptionMessage Resolver "not-supported" must be "GraphQL\Type\Definition\Type" "stdClass" given.