Skip to content

[DX][HttpKernel] Throw a sensible exception when controller has been removed #25339

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

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Dec 5, 2017

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25335
License MIT
Doc PR ø

Following on #25201, we need to throw the same kind of sensible exception when the controller service is not found.

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) HttpKernel Bug labels Dec 5, 2017
@sroze sroze force-pushed the sensible-exception-when-controller-has-been-removed branch from 01cbffb to df6b238 Compare December 5, 2017 16:54
@@ -75,6 +75,8 @@ protected function createController($controller)
return $service;
}

$this->throwExceptionIfControllerWasRemoved($controller);
Copy link
Member

Choose a reason for hiding this comment

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

L70 can also fail for the same reason

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it's a good idea to add a similar check there too. Currently you would get this error:

The "app.my_controller" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that's fine, it fails with the following exception:

The "app.my_controller" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

Copy link
Member

Choose a reason for hiding this comment

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

It feels inconsistent to me to get different errors depending on how you configured the route.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @xabbuh :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored it and added another DX improvement for missing __invoke methods at the same time 😉

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Dec 6, 2017
@sroze sroze force-pushed the sensible-exception-when-controller-has-been-removed branch 2 times, most recently from 73136df to 524e148 Compare December 6, 2017 10:52
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

with minor wording suggestions

if (!$this->container->has($controller)) {
$this->throwExceptionIfControllerWasRemoved($controller);

throw new \LogicException(sprintf('The controller "%s" do not exists.', $controller));
Copy link
Member

Choose a reason for hiding this comment

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

Controller not found: service "%s" does not exist.

// invokable controller in the "service" notation
return $service;
if (!method_exists($service, '__invoke')) {
throw new \LogicException(sprintf('The controller "%s" cannot be called without a method name. Did you forget an "__invoke" method?', $controller));
Copy link
Member

Choose a reason for hiding this comment

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

Controller "%s" cannot [...]

@sroze sroze force-pushed the sensible-exception-when-controller-has-been-removed branch from 524e148 to 458d63f Compare December 6, 2017 11:59
@sroze
Copy link
Contributor Author

sroze commented Dec 6, 2017

Yep, I like your wording suggestions @nicolas-grekas. Changed 👍

@linaori
Copy link
Contributor

linaori commented Dec 6, 2017

I'm a bit confused here, are you referring to missing controllers or missing actions?

@sroze
Copy link
Contributor Author

sroze commented Dec 6, 2017

AFAIK "actions" are not an "official" Symfony thing. It's just a controller.

@fabpot
Copy link
Member

fabpot commented Dec 7, 2017

Thank you @sroze.

@fabpot fabpot merged commit 458d63f into symfony:3.4 Dec 7, 2017
fabpot added a commit that referenced this pull request Dec 7, 2017
…ler has been removed (sroze)

This PR was merged into the 3.4 branch.

Discussion
----------

[DX][HttpKernel] Throw a sensible exception when controller has been removed

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25335
| License       | MIT
| Doc PR        | ø

Following on #25201, we need to throw the same kind of sensible exception when the controller service is not found.

Commits
-------

458d63f Throw a sensible exception when controller has been removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DX DX = Developer eXperience (anything that improves the experience of using Symfony) HttpKernel Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants