Currently if e.g. some plugin has a malformed annotation, the site will simply crash on plugin discovery / when clearing caches.
From my apache error.log:
Uncaught PHP Exception Doctrine\\Common\\Annotations\\AnnotationException: "[Syntax Error] Expected Value, got 'Mymod custom text' at position 28 in class Drupal\\mymod\\Plugin\\Block\\Block_CustomText." at /PATH/TO/D8/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php line 42, referer: http://d8lab.loc/admin/config/development/performance
and the page response:
The website encountered an unexpected error. Please try again later.
Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected Value, got 'Mymod custom text' at position 28 in class Drupal\mymod\Plugin\Block\Block_CustomText. in Doctrine\Common\Annotations\AnnotationException::syntaxError() (line 42 of vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php).
Doctrine\Common\Annotations\DocParser->syntaxError('Value', Array) (Line: 861)
Doctrine\Common\Annotations\DocParser->Values() (Line: 833)
Doctrine\Common\Annotations\DocParser->MethodCall() (Line: 744)
Doctrine\Common\Annotations\DocParser->Annotation() (Line: 641)
Doctrine\Common\Annotations\DocParser->Annotations() (Line: 334)
Doctrine\Common\Annotations\DocParser->parse('/**
* @Block("mymod_custom_text", "Mymod custom text")
*/', 'class Drupal\mymod\Plugin\Block\Block_CustomText') (Line: 67)
Doctrine\Common\Annotations\SimpleAnnotationReader->getClassAnnotations(Object) (Line: 91)
Doctrine\Common\Annotations\SimpleAnnotationReader->getClassAnnotation(Object, 'Drupal\Core\Block\Annotation\Block') (Line: 145)
Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery->getDefinitions() (Line: 86)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions() (Line: 283)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 174)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('system_breadcrumb_block') (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('system_breadcrumb_block', Array) (Line: 76)
Drupal\Component\Plugin\PluginManagerBase->createInstance('system_breadcrumb_block', Array) (Line: 65)
Drupal\Core\Plugin\DefaultSingleLazyPluginCollection->initializePlugin('system_breadcrumb_block') (Line: 57)
Drupal\block\BlockPluginCollection->initializePlugin('system_breadcrumb_block') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection->get('system_breadcrumb_block') (Line: 45)
Drupal\block\BlockPluginCollection->get('system_breadcrumb_block') (Line: 138)
Drupal\block\Entity\Block->getPlugin() (Line: 113)
Drupal\block\BlockAccessControlHandler->checkAccess(Object, 'view', Object) (Line: 93)
Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'view', NULL, 1) (Line: 340)
Drupal\Core\Entity\Entity->access('view', NULL, 1) (Line: 56)
Drupal\block\BlockRepository->getVisibleBlocksPerRegion(Array) (Line: 137)
Drupal\block\Plugin\DisplayVariant\BlockPageVariant->build() (Line: 259)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
I think we should do something other than just crash and burn.
However, it is important that the developer, or someone, notices that something is wrong.
My proposal:
- Skip, but remember, broken plugin annotations.
- Continue as usual, with the broken plugins omitted.
- If the cache is being cleared by a privileged user or on the cli, show a message mentioning where the broken annotations were found.
- In any case, log the event.
- Optionally, report broken plugin annotations in the status report page.