I have a patch to add some custom handling of 500 errors that run through the code in errors.inc, so that it returns a themed page in those cases.
This works well in certain conditions, but I have an error that occurred with a misnamed twig template, so I got
Twig_Error_Loader: Template "@mytheme/search-result/search-result--event.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "@mytheme/search-result/search-result--event.twig" in the Drupal theme registry.) in "themes/custom/mytheme/templates/node/node--admissions-event--search-result.html.twig" at line 1. in Twig_Loader_Chain->getCacheKey() (line 129 of /var/www/mytheme-qa/site/vendor/twig/twig/lib/Twig/Loader/Chain.php).
After some digging I see that this error is generated here: /core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php
if ($ throw) { throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" in the Drupal theme registry.', $ name)); }
The problem is this type of error isn’t handled by Drupal. It’s a Twig engine error. So an exception subscriber doesn’t catch this.
Any suggestions on how to return a themed 500 page in fatal error cases like this at the theme layer?