Skip to content

Commit

Permalink
Output class in exception when AutoRegister fails
Browse files Browse the repository at this point in the history
When a public class that is wrongly configured or misplaced fails, it's
hard to debug. This is because it will fail because of a `getName()`
function call on a null object. To improve developer experience, output
the classname it fails on.
  • Loading branch information
martijnboers authored and ruudk committed Apr 25, 2019
1 parent 8ca920f commit e6629a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/DependencyInjection/Compiler/AutoRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SimpleBus\SymfonyBridge\DependencyInjection\Compiler;

use RuntimeException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand Down Expand Up @@ -58,6 +59,11 @@ public function process(ContainerBuilder $container)
continue;
}

if ($parameters[0]->getClass() === null) {
throw new RuntimeException(sprintf('Could not get auto register class %s because the first parameter %s of public method %s should be have a class typehint. Either specify the typehint, make the function non-public, or disable auto registration.', $method->class,
$parameters[0]->getName(), $method->getName()));
}

// get the class name
$handles = $parameters[0]->getClass()->getName();

Expand Down

0 comments on commit e6629a4

Please sign in to comment.