hyva-themes / magento2-hyva-admin

This module aims to make creating grids and forms in the Magento 2 adminhtml area joyful and fast.
https://hyva-themes.github.io/magento2-hyva-admin/
BSD 3-Clause "New" or "Revised" License
168 stars 39 forks source link

Grid page broken by module declared in composer as require-dev #53

Closed mirkocesaro closed 3 years ago

mirkocesaro commented 3 years ago

I am working on Magento 2.4.1 and I found this error in my log while I visit an admin page with Hyva-admin grid:

report.CRITICAL: TypeError: Return value of Hyva\Admin\Model\Config\HyvaConfigDirs::moduleDir() must be of the type string, null returned in /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/HyvaConfigDirs.php:51

and, of course, the grid is not visible.

This is related to a module not registered with the module registrar but also present in the config.php file.

How this is possible?

In my local env, I work with a dev module required by composer. It is added in the config.php file as active and pushed it. The pipeline, to deploy the code on the server, uses the composer install --no-dev and remove the module from the vendor but the module is still in config.php file.

I have to check the pipeline to understand why the bin/magento setup:upgrade --keep-generated does not remove the dev modules. But I open the issue here anyway because could be useful to fix it.

How to reproduce it

Add an unexistent module to the config.php, clean the config cache and open an admin page with the hyva grid.

Workaround

As @Vinai suggested to me, add an explicit type conversion to \Hyva\Admin\Model\Config\HyvaConfigDirs::moduleDir method like:

private function moduleDir(string $module): string
{
    return (string) $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $module);
}

Stack trace:

Stack trace:
#0 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/HyvaConfigDirs.php(69): Hyva\Admin\Model\Config\HyvaConfigDirs->moduleDir()
#1 [internal function]: Hyva\Admin\Model\Config\HyvaConfigDirs->getHyvaConfigDirNames()
#2 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/HyvaConfigDirs.php(61): array_map()
#3 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/DefinitionConfigFiles.php(35): Hyva\Admin\Model\Config\HyvaConfigDirs->list()
#4 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/GridConfigReader.php(78): Hyva\Admin\Model\Config\DefinitionConfigFiles->getConfigDefinitionFiles()
#5 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/Config/GridConfigReader.php(73): Hyva\Admin\Model\Config\GridConfigReader->readGridConfig()
#6 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/HyvaGridDefinition.php(52): Hyva\Admin\Model\Config\GridConfigReader->getGridConfiguration()
#7 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/HyvaGridDefinition.php(83): Hyva\Admin\Model\HyvaGridDefinition->getGridConfiguration()
#8 /var/www/current/vendor/hyva-themes/module-magento2-admin/Model/HyvaGridSourceFactory.php(42): Hyva\Admin\Model\HyvaGridDefinition->getSourceConfig()
#9 /var/www/current/vendor/hyva-themes/module-magento2-admin/ViewModel/HyvaGridViewModel.php(201): Hyva\Admin\Model\HyvaGridSourceFactory->createFor()
#10 /var/www/current/vendor/hyva-themes/module-magento2-admin/ViewModel/HyvaGridViewModel.php(253): Hyva\Admin\ViewModel\HyvaGridViewModel->getGridSourceModel()
#11 /var/www/current/vendor/hyva-themes/module-magento2-admin/view/adminhtml/templates/grid.phtml(9): Hyva\Admin\ViewModel\HyvaGridViewModel->getNavigation()
#12 /var/www/current/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/var/www/curren...')
#13 /var/www/current/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render()
#14 /var/www/current/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent()
#15 /var/www/current/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}()
#16 /var/www/current/generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php(23): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins()
#17 /var/www/current/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php\Interceptor->render()
#18 /var/www/current/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView()
#19 /var/www/current/vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Framework\View\Element\Template->_toHtml()
#20 /var/www/current/vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#21 /var/www/current/vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#22 /var/www/current/vendor/magento/framework/View/Layout.php(566): Magento\Framework\View\Element\AbstractBlock->toHtml()
#23 /var/www/current/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderBlock()
#24 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#25 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#26 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#27 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#28 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#29 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#30 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#31 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#32 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#33 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#34 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#35 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#36 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#37 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#38 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#39 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#40 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#41 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#42 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#43 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#44 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#45 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#46 /var/www/current/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement()
#47 /var/www/current/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer()
#48 /var/www/current/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement()
#49 /var/www/current/vendor/magento/framework/View/Layout.php(963): Magento\Framework\View\Layout->renderElement()
#50 /var/www/current/generated/code/Magento/Framework/View/Layout/Interceptor.php(50): Magento\Framework\View\Layout->getOutput()
#51 /var/www/current/vendor/magento/framework/View/Result/Page.php(258): Magento\Framework\View\Layout\Interceptor->getOutput()
#52 /var/www/current/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render()
#53 /var/www/current/generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php(23): Magento\Framework\View\Result\Layout->renderResult()
#54 /var/www/current/vendor/magento/framework/App/Http.php(120): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult()
#55 /var/www/current/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http->launch()
#56 /var/www/current/pub/index.php(40): Magento\Framework\App\Bootstrap->run()
#57 {main} [] []
Vinai commented 3 years ago

Thank you for this excellent report and for including the underlying reason!

In my local env, I work with a dev module required by composer. It is added in the config.php file as active and pushed it. The pipeline, to deploy the code on the server, uses the composer install --no-dev and remove the module from the vendor but the module is still in config.php file.

Very interesting and useful! 🎉 Now I can add the type-cast to the code without without having a bad feeling about it :)