EntityTypeManager::getHandler() exception is not always accurate

Created on 17 December 2018, almost 7 years ago
Updated 4 November 2025, 5 days ago

EntityTypeManager::getHandler() can throw an exception that says:

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

However, this can be thrown if the entity type specifies the handler of the type in question, but the class isn't found.

That can happen for example if:

- there is a typo in the class name in the entity type annotation
- the handler class doesn't autoload correctly, for example, if the namespace is incorrect
- the class doesn't exist at all

In all these circumstances, the exception message is directing the developer to the wrong problem.

This is because getHandler() calls EntityType::getHandlerClass(), which in turn calls hasHandlerClass(), and that checks the class exists:

  public function hasHandlerClass($handler_type, $nested = FALSE) {
    $handlers = $this->getHandlerClasses();
    if (!isset($handlers[$handler_type]) || ($nested && !isset($handlers[$handler_type][$nested]))) {
      return FALSE;
    }
    $handler = $handlers[$handler_type];
    if ($nested) {
      $handler = $handler[$nested];
    }
    return class_exists($handler);
  }
🐛 Bug report
Status

Active

Version

11.0 🔥

Component

entity system

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024