Skip to content

Commit

Permalink
Remove try/catch for error/exception thrown on type loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Oct 18, 2018
1 parent cc02858 commit 7d2e449
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
37 changes: 6 additions & 31 deletions src/Resolver/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Security/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 0 additions & 12 deletions tests/Resolver/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7d2e449

Please sign in to comment.