Pronovix / swagger_ui_formatter

Swagger UI Field Formatter for Drupal
GNU General Public License v2.0
3 stars 12 forks source link

Class 'Drupal\bootstrap\Bootstrap' not found error #69

Open henokmikre opened 3 years ago

henokmikre commented 3 years ago

I noticed this error after upgrading to version 3 (3.2 to be specific). Although the problem is ultimately a core issue, it is more frequently evident since swagger_ui_formatter now calls loadActiveTheme() around line 111 of SwaggerUiLibraryDiscovery.php. The issue has been reported in drupal.org/i/2667062 and in drupal.org/i/2853398. There was a suggestion that it happens if "rebuild theme" is checked in devel, but I have noticed it even with that option unchecked. I am wondering if anyone has a suggestion for a workaround.

mxr576 commented 2 years ago

Thanks for the D.o issue references but you can explain the steps to reproduce this problem by using the Swagger UI FF module?

driverok commented 1 year ago

Steps might be the following

  1. Clear the cache
  2. Go to any non-admin page (ex. homepage)
  3. Go to /admin/config or /admin/reports/status page.
  4. The message comes up that Bootstrap class can not be found:
  5. Clear cache again
  6. Go to /admin/config or /admin/reports/status page.
  7. Pages are loading without any issues.

Error: Class 'Drupal\bootstrap\Bootstrap' not found in include_once() (Line: 147) Drupal\Core\Extension\Extension->load() (Line: 35) twig_init() call_user_func() (Line: 144) Drupal\Core\Theme\ThemeInitialization->loadActiveTheme() (Line: 111) Drupal\swagger_ui_formatter\Service\SwaggerUiLibraryDiscovery->libraryDirectory() (Line: 40) swagger_ui_formatter_requirements() call_user_func_array() (Line: 403) Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 111) Drupal\system\SystemManager->listRequirements() (Line: 49) Drupal\system\Controller\SystemInfoController->status() call_user_func_array() (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 68) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 67) Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 57) Drupal\Core\StackMiddleware\Session->handle() (Line: 47) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23) Stack\StackedHttpKernel->handle() (Line: 708) Drupal\Core\DrupalKernel->handle() (Line: 19)

As a solution:

  1. Add listInfo() method call inside of libraryDirectory() method
  2. Programmatically clear theme cache before getActiveThemeByName() call
  3. Register theme classes manually

Option 1 as for me looks more promising.

mxr576 commented 1 year ago

Can anybody reproduce this issue with ANY other theme than bootstrap? (Because Drupal\bootstrap\Bootstrap is a class from that theme). Themes vs autoloading in Drupal is just weird...

mxr576 commented 1 year ago

I guess this is their dirty trick which is not working in all cases... https://git.drupalcode.org/project/bootstrap/-/blob/8.x-4.x/autoload-fix.php https://git.drupalcode.org/project/bootstrap/-/blob/8.x-4.x/src/Traits/FormAutoloadFixTrait.php#L25

alenastanul87 commented 1 year ago

The problem is still reproducible. Main root cause, that the registration the namespaces of installed themes is separately from registration a list of namespaces with PSR-4 directories from container.namespaces. There is a drupal.org issue on this problem. Therefore, while there are no fixes in the core about this problem, the attached patch can be applied: swagger_ui_formatter_fixed_bootstrap_class_not_found_69.patch

mxr576 commented 1 year ago

Thanks @alenastanul87 for the detailed root cause analyzes.

However, I am still hasitant to commit any changes related to this issue to the module if only Bootstrap based themes are affected. Currently, we are not aware of any other way to trigger this error...

Being that said:

alenastanul87 commented 1 year ago

Thanks @mxr576 for your comment.

Firstly, I compared the page load speed with the code $this->themeHandler->listInfo() and without. I didn't find a difference. It's worth noting there is a handling cache in getList() function.

Secondly, the problem exists until now. We are facing it. But the work on the drupal.org issue has been going on since 2018. Looking optimistically it will ever be completed. But we don't know the date yet.

Thirdly, considering your comments I propose another version of the patch: swagger_ui_formatter_fixed_bootstrap_class_not_found_with_catching_69.patch.

mxr576 commented 1 year ago

Quick answer before I leave for the weekend :) Could you please create a PR instead of sharing suggestions in patches? thank you