8000 [DX] Improve exception message when AbstractController::getParameter fails by curry684 · Pull Request #27443 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DX] Improve exception message when AbstractController::getParameter fails #27443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finetune exception message
  • Loading branch information
curry684 committed May 31, 2018
commit f3e01e0fdde015c32fb042806e6deb3cbbe06936
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ public function setContainer(ContainerInterface $container)
protected function getParameter(string $name)
{
if (!$this->container->has('parameter_bag')) {
throw new ServiceNotFoundException('parameter_bag', null, null, array(),
'The "parameter_bag" service could not be located. Ensure that symfony/dependency-injection 4.1.0 or higher '.
'is installed and that the controller is either set to be autoconfigured or wired manually to inject it');
$message = 'The "parameter_bag" service could not be located. ';
if (!interface_exists(ContainerBagInterface::class)) {
$message .= 'Upgrade symfony/dependency-injection to at least 4.1.0 to have it injected automatically.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggesting to install/upgrade symfony/dependency-injection does not seem relevant as framework-bundle requires it ^4.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, hadn't bothered to doublecheck that because it was the original message and I assumed it to have a reason.

} else {
$message .= 'Ensure that the controller is either set to be autoconfigured or wired manually to inject it.';
}

throw new ServiceNotFoundException('parameter_bag', null, null, array(), $message);
}

return $this->container->get('parameter_bag')->get($name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testGetParameter()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessage The "parameter_bag" service could not be located
* @expectedExceptionMessage The "parameter_bag" service could not be located.
*/
public function testMissingParameterBag()
{
Expand Down
0