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",
\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 patchAdd new test to validate exception messageTest- Review
User interface changes
Before patch

After patch

API changes
none
Data model changes
none
Release notes snippet
none
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2820411-after-patch.png | 33.68 KB | akhil babu |
| #31 | 2820411-before-patch.png | 30.04 KB | akhil babu |
Issue fork drupal-2820411
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:
- 2820411-improve-the-exception
changes, plain diff MR !5673
Comments
Comment #15
larowlanComment #20
akhil babuI 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.
Comment #21
akhil babuComment #22
joachim commentedIt'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!
Comment #23
akhil babuThanks @joachim.
Fixed the test. Also added a new test for the new exception message.
Comment #24
smustgrave commentedFor good practice as a novice task issue summary should follow the standard issue template.
Comment #25
akhil babuComment #26
akhil babuComment #27
akhil babuComment #28
akhil babuComment #29
akhil babuComment #30
akhil babuComment #31
akhil babuComment #32
akhil babuComment #33
akhil babuComment #34
akhil babuUpdated the issue summary. Moving back to needs review
Comment #35
smustgrave commentedIssue 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!
Comment #36
quietone commentedThanks 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.
Comment #37
akhil babuThanks for reviewing. I've Committed the proposed changes. Moving back to Needs review
Comment #38
smustgrave commentedFeedback has been addressed.
Comment #39
larowlanIssue credits
Comment #40
larowlanLeft 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).Comment #41
akhil babuI have updated the MR as per the review comments.
@larowlan The exception message in
\Drupal\Core\Entity\EntityTypeManager::getFormObjectalso 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 existComment #42
smustgrave commentedFeedback appears to be addressed.
Comment #45
quietone commentedI 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!