cancel
Showing results for 
Search instead for 
Did you mean: 

Silence Setup version for module is not specified exception

SOLVED

Silence Setup version for module is not specified exception

Hello,

by default Magento 2 throws an exception "Setup version for module 'Borntocreate_ChannelAdvisorConnector' is not specified" exception.

 

Is there a way to silence this exception and for example log it and just skip loading the module?


I dont want my store to be down for some minutes just because I havent upgraded my db yet.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Silence Setup version for module is not specified exception

Ive overridden the \Magento\Frameowkr\Module\Plugin\DbStatusValidator Plugin which does exactly what I want.

Im having the same concerns that there is, of course, a reason why the database has to be upgraded otherwise the module is not usable.

Im having the same concerns although I will still share my code for people willing to take the risk:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/di.xsd">
    <preference for="Magento\Framework\Module\Plugin\DbStatusValidator" type="Vendor\Module\Plugin\CatchSetupUpgradeExceptionPlugin" />
</config>

 

<?php


namespace Vendor\Module\Plugin;


use Magento\Framework\App\FrontController;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Cache\FrontendInterface as FrontendCacheInterface;
use Magento\Framework\Module\DbVersionInfo;

class CatchSetupUpgradeExceptionPlugin extends \Magento\Framework\Module\Plugin\DbStatusValidator
{

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * @var FrontendCacheInterface
     */
    protected $cache;

    /**
     * @var DbVersionInfo
     */
    protected $dbVersionInfo;

    public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVersionInfo, \Psr\Log\LoggerInterface $logger)
    {

        parent::__construct($cache, $dbVersionInfo);

        $this->logger = $logger;
        $this->dbVersionInfo = $dbVersionInfo;
        $this->cache = $cache;

    }

    public function beforeDispatch(FrontController $subject, RequestInterface $request)
    {

        $this->logger->info(__METHOD__);

        try {
            parent::beforeDispatch($subject, $request);
        } catch (\UnexpectedValueException $ex) {
            $this->logger->critical($ex);
        }
    }

}

This actually silences the exception and displays the frontend as normal.

View solution in original post

2 REPLIES 2

Re: Silence Setup version for module is not specified exception

No. If you made an update your must switch your store in the maintenance mode for some minutes, because you must upgrade your database and do a static deploy for the changes.

 

There is no solution. The problem is if you upgrade your database and at the same time a customer take an order the database crashed.

---
If my answer is useful, please Accept as Solution & give Kudos

Re: Silence Setup version for module is not specified exception

Ive overridden the \Magento\Frameowkr\Module\Plugin\DbStatusValidator Plugin which does exactly what I want.

Im having the same concerns that there is, of course, a reason why the database has to be upgraded otherwise the module is not usable.

Im having the same concerns although I will still share my code for people willing to take the risk:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/di.xsd">
    <preference for="Magento\Framework\Module\Plugin\DbStatusValidator" type="Vendor\Module\Plugin\CatchSetupUpgradeExceptionPlugin" />
</config>

 

<?php


namespace Vendor\Module\Plugin;


use Magento\Framework\App\FrontController;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Cache\FrontendInterface as FrontendCacheInterface;
use Magento\Framework\Module\DbVersionInfo;

class CatchSetupUpgradeExceptionPlugin extends \Magento\Framework\Module\Plugin\DbStatusValidator
{

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * @var FrontendCacheInterface
     */
    protected $cache;

    /**
     * @var DbVersionInfo
     */
    protected $dbVersionInfo;

    public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVersionInfo, \Psr\Log\LoggerInterface $logger)
    {

        parent::__construct($cache, $dbVersionInfo);

        $this->logger = $logger;
        $this->dbVersionInfo = $dbVersionInfo;
        $this->cache = $cache;

    }

    public function beforeDispatch(FrontController $subject, RequestInterface $request)
    {

        $this->logger->info(__METHOD__);

        try {
            parent::beforeDispatch($subject, $request);
        } catch (\UnexpectedValueException $ex) {
            $this->logger->critical($ex);
        }
    }

}

This actually silences the exception and displays the frontend as normal.