Skip to content

Conversation

andirosu
Copy link

@andirosu andirosu commented Apr 7, 2025

Move condition to prevent Error getName on null

Description

Move the condition before the variable alocation, so that it will no longer throw an Error if category is actually null.

Fixed Issues (if relevant)

Found a bug in production, instead of patching it locally I've created this PR. See trace at the end.

Manual testing scenarios

  1. install the latest available module via Composer, configuring Magento FPC to Varnish. set nginx as reverse proxy and enabling Varnish.
  2. Add blog posts, categories and tags
  3. open a blog category and observe the An error has happened during application run. See exception log for details. instead of the magento menu.
  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)

The trace that made me dig for this:

Stack trace:
#0 .../vendor/magento/framework/View/Element/AbstractBlock.php(288): Mageplaza\Blog\Block\Category\Listpost->_prepareLayout()
#1 .../vendor/magento/framework/View/Layout/Generator/Block.php(149): Magento\Framework\View\Element\AbstractBlock->setLayout()
#2 .../vendor/magento/framework/View/Layout/GeneratorPool.php(93): Magento\Framework\View\Layout\Generator\Block->process()
#3 .../vendor/magento/framework/View/Layout.php(365): Magento\Framework\View\Layout\GeneratorPool->process()
#4 .../vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->generateElements()
#5 .../vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent()
#6 .../vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#7 .../generated/code/Magento/Framework/View/Layout/Interceptor.php(32): Magento\Framework\View\Layout\Interceptor->___callPlugins()
#8 .../vendor/magento/framework/View/Layout/Builder.php(129): Magento\Framework\View\Layout\Interceptor->generateElements()
#9 .../vendor/magento/framework/View/Page/Builder.php(65): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
#10 .../vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
#11 .../vendor/magento/framework/View/Page/Config.php(227): Magento\Framework\View\Layout\Builder->build()
#12 .../vendor/magento/framework/View/Page/Config.php(240): Magento\Framework\View\Page\Config->build()
#13 .../vendor/magento/framework/App/View.php(170): Magento\Framework\View\Page\Config->publicBuild()
#14 .../vendor/magento/framework/App/View.php(114): Magento\Framework\App\View->loadLayoutUpdates()
#15 .../vendor/magento/module-page-cache/Controller/Block.php(126): Magento\Framework\App\View->loadLayout()
#16 .../vendor/magento/module-page-cache/Controller/Block/Esi.php(19): Magento\PageCache\Controller\Block->_getBlocks()
#17 .../vendor/magento/framework/Interception/Interceptor.php(58): Magento\PageCache\Controller\Block\Esi->execute()
#18 .../vendor/magento/framework/Interception/Interceptor.php(138): Magento\PageCache\Controller\Block\Esi\Interceptor->___callParent()
#19 .../vendor/magento/framework/Interception/Interceptor.php(153): Magento\PageCache\Controller\Block\Esi\Interceptor->Magento\Framework\Interception\{closure}()
#20 .../generated/code/Magento/PageCache/Controller/Block/Esi/Interceptor.php(23): Magento\PageCache\Controller\Block\Esi\Interceptor->___callPlugins()
#21 .../vendor/magento/framework/App/Action/Action.php(111): Magento\PageCache\Controller\Block\Esi\Interceptor->execute()
#22 .../vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch()
#23 .../vendor/magento/framework/Interception/Interceptor.php(138): Magento\PageCache\Controller\Block\Esi\Interceptor->___callParent()
#24 .../vendor/magento/framework/Interception/Interceptor.php(153): Magento\PageCache\Controller\Block\Esi\Interceptor->Magento\Framework\Interception\{closure}()
#25 .../generated/code/Magento/PageCache/Controller/Block/Esi/Interceptor.php(32): Magento\PageCache\Controller\Block\Esi\Interceptor->___callPlugins()
#26 .../vendor/magento/framework/App/FrontController.php(245): Magento\PageCache\Controller\Block\Esi\Interceptor->dispatch()
#27 .../vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()
#28 .../vendor/magento/framework/App/FrontController.php(146): Magento\Framework\App\FrontController->processRequest()
#29 .../vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()
#30 .../vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()
#31 .../vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(99): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#32 .../vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch()
#33 .../vendor/amasty/aminvisiblecaptcha/Plugin/Framework/App/FrontControllerInterface/ValidateCaptcha.php(124): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#34 .../vendor/magento/framework/Interception/Interceptor.php(135): Amasty\InvisibleCaptcha\Plugin\Framework\App\FrontControllerInterface\ValidateCaptcha->aroundDispatch()
#35 .../vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(72): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#36 .../vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch()
#37 .../vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#38 .../generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()
#39 .../vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()
#40 .../vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Http->launch()
#41 .../vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\Http\Interceptor->___callParent()
#42 .../vendor/magento/module-application-performance-monitor/Plugin/ApplicationPerformanceMonitor.php(38): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#43 .../vendor/magento/framework/Interception/Interceptor.php(135): Magento\ApplicationPerformanceMonitor\Plugin\ApplicationPerformanceMonitor->aroundLaunch()
#44 .../vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#45 .../generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http\Interceptor->___callPlugins()
#46 .../vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#47 .../pub/index.php(30): Magento\Framework\App\Bootstrap->run()
#48 {main} {"exception":"[object] (Error(code: 0): Call to a member function getName() on null at .../vendor/mageplaza/magento-2-blog-extension/Block/Category/Listpost.php:84)"}

Move condition to prevent Error getName on null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant