\Drupal\Core\Entity\EntityTypeManagerInterface::getStorage() documents (without description text) that it might throw \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException. Actually, though, it can also throw \Drupal\Component\Plugin\Exception\PluginNotFoundException, namely if the entity type doesn't even exist.

Code to test:

try {
  \Drupal::entityTypeManager()->getStorage('foo');
}
catch (\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException $e) {}

Comments

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new780 bytes

This would fix the docs.

Alternately, we could also document that the method can throw \Drupal\Component\Plugin\Exception\PluginException, which is the parent of both other exceptions.

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.

borisson_’s picture

This patch still applies, but I don't see where PluginNotFoundException is thrown from.

drunken monkey’s picture

Thanks for reviewing!

This patch still applies, but I don't see where PluginNotFoundException is thrown from.

\Drupal\Core\Entity\EntityTypeManager::getStorage()
-> \Drupal\Core\Entity\EntityTypeManager::getHandler()
  -> \Drupal\Core\Entity\EntityTypeManager::getDefinition()
     Throws PluginNotFoundException if entity type doesn't exist.
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for explaining, looks great!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 64fbabd716 to 8.6.x and 6f911f61dc to 8.5.x. Thanks!

As this is a docs only improvement backported to 8.5.x.

  • alexpott committed 64fbabd on 8.6.x
    Issue #2899051 by drunken monkey: Properly document possible exceptions...

  • alexpott committed 6f911f6 on 8.5.x
    Issue #2899051 by drunken monkey: Properly document possible exceptions...

Status: Fixed » Closed (fixed)

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