Problem/Motivation

EntityTypeManager::getHandler() will throw an exception if either the handler or its associated class does not exist. The exception message will be in the format

''The "%s" entity type did not specify a %s handler.''

This message should be adjusted to include information about both scenarios.

Steps to reproduce

Case-1: Handler does not exist.
Run the following code to see the exception.

\Drupal::entityTypeManager()->getHandler('node', 'invalid_handler');

Case-2: Handler class does not exist.
Edit "handlers" annotation of node entity (core/modules/node/src/Entity/Node.php) and change class name of any one of the handlers. eg:

 *   handlers = {
 *     "views_data" = "Drupal\node\InvalidClass",
  • Clear cache
  • Run \Drupal::entityTypeManager()->getHandler('node', 'views_data')
  • In both cases, exception message is in the format "The "%s" entity type did not specify a %s handler.".

    Proposed resolution

    Update the exception message.

    When handler does not exist: "The "%s" entity type did not specify a %s handler.".
    When handler class does not exist: "The %s handler of the "%s" entity type specifies a non-existent class "%s"

    Remaining tasks

    • Create a patch
    • Add new test to validate exception message
    • Test
    • Review

    User interface changes

    Before patch

    https://www.drupal.org/files/issues/2023-12-20/2820411-before-patch.png

    After patch

    https://www.drupal.org/files/issues/2023-12-20/2820411-after-patch.png

    API changes

    none

    Data model changes

    none

    Release notes snippet

    none

    Issue fork drupal-2820411

    Command icon Show commands

    Start within a Git clone of the project using the version control instructions.

    Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    joachim created an issue. See original summary.

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

    Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.4.x-dev » 8.5.x-dev

    Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

    Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

    Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

    Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

    Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

    Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

    Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

    Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

    Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.4.x-dev » 9.5.x-dev

    Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

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

    Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    larowlan’s picture

    Title: misleading exception message when an entity handler class does not exist » Improve the exception message when an entity handler class does not exist
    Issue tags: +Novice, +Bug Smash Initiative

    Akhil Babu made their first commit to this issue’s fork.

    Akhil Babu changed the visibility of the branch 2820411-improve-the-exception to hidden.

    Akhil Babu changed the visibility of the branch 2820411-improve-the-exception to active.

    akhil babu’s picture

    I have updated the exception message as follows
    When the handler does not exist: The "%s" entity type did not specify a %s handler.
    When the handler class does not exist: The %s handler of the "%s" entity type specifies a non-existent class "%s".

    But, not sure why the pipeline is failing.

    akhil babu’s picture

    Status: Active » Needs review
    joachim’s picture

    Status: Needs review » Needs work

    It's a pain to find the failure in the logs -- in the raw log at https://drupal-gitlab-job-artifacts.s3.us-west-2.amazonaws.com/34/dd/34d... it's this:

    Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetHandlerMissingHandler
    Prophecy\Exception\Call\UnexpectedCallException: Unexpected method call on
    Double\EntityTypeInterface\P6:
    - getHandlerClasses(

    )
    expected calls were:
    - getHandlerClass(
    exact("storage")
    )
    - getLinkTemplates(

    )
    - getClass(

    )
    - setClass(
    exact("Mock_EntityInterface_5a25fd53")
    )

    So the mock needs updating for the new method call.

    Though I am surprised there is no test coverage of the exception message we're changing!

    akhil babu’s picture

    Status: Needs work » Needs review

    Thanks @joachim.
    Fixed the test. Also added a new test for the new exception message.

    smustgrave’s picture

    Status: Needs review » Needs work

    For good practice as a novice task issue summary should follow the standard issue template.

    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    StatusFileSize
    new30.04 KB
    new33.68 KB
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Status: Needs work » Needs review

    Updated the issue summary. Moving back to needs review

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Issue summary seems good.

    @Akhil Babu just FYI this ticket was tagged novice, you did nothing wrong working on it, but based on the number of posts you now have and work on other tickets believe you should be good to work on non novice issues now. Good job!

    quietone’s picture

    Status: Reviewed & tested by the community » Needs work

    Thanks for helping developers.

    I'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions.

    I reviewed the MR and left suggestions, so setting to Needs work.

    akhil babu’s picture

    Status: Needs work » Needs review

    Thanks for reviewing. I've Committed the proposed changes. Moving back to Needs review

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Feedback has been addressed.

    larowlan’s picture

    Issue credits

    larowlan’s picture

    Status: Reviewed & tested by the community » Needs work

    Left some suggestions on the MR

    Can we also get a follow-up for a similar fix in \Drupal\Core\Entity\EntityTypeManager::getFormObject (if one does not already exist).

    akhil babu’s picture

    Status: Needs work » Needs review

    I have updated the MR as per the review comments.
    @larowlan The exception message in \Drupal\Core\Entity\EntityTypeManager::getFormObject also has to be updated when the form class does not exist. I have create a new issue for that. #3418298: Improve the exception message when an entity form class does not exist

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community

    Feedback appears to be addressed.

    • quietone committed 5a571f6f on 11.x
      Issue #2820411 by Akhil Babu, smustgrave, larowlan, joachim, quietone:...

    • quietone committed ae84c94c on 10.2.x
      Issue #2820411 by Akhil Babu, smustgrave, larowlan, joachim, quietone:...
    quietone’s picture

    Status: Reviewed & tested by the community » Fixed

    I reviewed this again and all I notice is that it would be helpful is we had standards for dataproviders. But that is something for the Coding Standards project.

    Committed 5a571f6 and pushed to 11.x.
    Committed ae84c94 and pushed to 10.2.x.

    Thanks!

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.