Problem/Motivation

These routes have been wrong since they were added (in #2362517: Improve default 403/404 exception HTML subscriber: don't duplicate the page render pipeline, use the routing system — add system.403 and system.404 routes and #2472371: Exception shown on 401 Unauthorized.

The problem lies in \Drupal\Core\Controller\ControllerResolver::createController() It claims to want either service:method or class::method, note 1 vs 2 colons. From #2.

Proposed resolution

Fix them

Remaining tasks

Find out why HEAD is passing, and write tests
Add exception messages.
A title change

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
1.05 KB
tim.plunkett’s picture

The problem lies in \Drupal\Core\Controller\ControllerResolver::createController()
It claims to want either service:method or class::method, note 1 vs 2 colons.

When originally added in #1875504: Add the possibility to use services as controllers, it followed that expectation.
But when #2165475: Provide a generic class resolver went in, it now will accept a class or a service, followed by either : or ::, and a method name.

I only noticed because PHPStorm was smart enough to flag it.

Should we rewrite ControllerResolver::createController() to be more strict again?
If not, we cannot write tests for this.

dawehner’s picture

I think we should make it strict and throw a damn stupid exception

Note: https://github.com/symfony/symfony/blob/2aeaa22e3171b5e1f10f2cc2a7ff7f66... also does not support that directly ...

Crell’s picture

Yes, let's be strict about it. Consistent expectations. But don't throw a damned stupid exception. Throw a smart, helpful exception that tells developers what they screwed up. :-)

dawehner’s picture

Oh yeah with stupid I meant a in your face exception, something which fails early, as long you still have the context available.

tim.plunkett’s picture

Issue tags: -Needs tests
FileSize
4.29 KB
3.24 KB

Now ControllerResolver *and* ClassResolver are ContainerAware, and both have $this->container->has() and class_exists() checks.

I did not spend time picking an exception class or writing a message

Status: Needs review » Needs work

The last submitted patch, 6: 2507885-system-5.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
4.72 KB
442 bytes

whoops :)

mgifford’s picture

Status: Needs review » Needs work

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Is this still relevant?

quietone’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work
Issue tags: +Needs reroll

Yes, this is still valid, system.routing.yml has Controllers with a single ':' instead of '::'.

ravi.shankar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.86 KB
5.33 KB

Added reroll of patch #8 on Drupal 9.4.x.

andypost’s picture

  1. +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
    @@ -105,10 +108,16 @@ protected function createController($controller) {
    +        throw new \LogicException('service NOPE');
    ...
    +        throw new \LogicException('class NOPE');
    

    instead of NOPE it would be helpful to show "$class_or_service"

  2. +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
    @@ -95,10 +96,31 @@ public function providerTestCreateController() {
    +   * @expectedException \LogicException
    +   * @expectedExceptionMessage service NOPE
    ...
    +   * @expectedException \LogicException
    +   * @expectedExceptionMessage class NOPE
    

    still needs re-roll as this annotations are deprecated

pooja saraah’s picture

Fixed failed commands on #23
Attached interdiff

andypost’s picture

Expected exception should be in code, not in doc-blocks

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
4.79 KB
2.12 KB

Made changes as per comment #24, please review.

Status: Needs review » Needs work

The last submitted patch, 27: 2507885-27.patch, failed testing. View results

andypost’s picture

In related #2531564: Fix leaky and brittle container serialization solution there could be a special method to detect public services in container

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.