Magento 2 Magento\Framework\Exception\LocalizedException through exception, but didn't track anything in error log

magento.stackexchange https://magento.stackexchange.com/questions/331441

  •  15-04-2021
  •  | 
  •  

Question

When applying laygered navigation filter in my Magento 2, In Developer Mode I got this error,

1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): sorry, something went wrong. You can find out more in the error log

But the problem is that nothing is tracked in whether the Apache error log or the Magento log. So I don't know how to diagnose the issue.

Any ideas on how to debug when seeing errors like this?


Update,

If I turn Production Mode on, the Exception #0 (Magento\Framework\Exception\LocalizedException): error mesesage is gone, and it displays an empty page, but I in developer tools in my browser it says "JavaScript seems to be disabled in your browser".

enter image description here

But I'm sure it's nothing to do with Javascript on my browser. I've tried with different browsers on different computers, I got the same error.

Was it helpful?

Solution

You can get this error on two times.

  • When Product collection is called.
  • When Advance Search Collection is called.

On classes

  • Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection.
  • Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection.

I guess that you have issue on collection call.

I guess that you need to do an indexing.

OTHER TIPS

✅How to fix it

Modify the Mageplaza_LayeredNavigation module's existing code to use the logger as follows:

app/code/Mageplaza/LayeredNavigation/Model/ResourceModel/Fulltext/Collection.php::497-501
function _renderFiltersBefore(){
    ...
    try {
        $this->searchResult = $this->getSearch()->search($searchCriteria);
    } catch (Exception $e) {
        $this->_logger->error( $e->getMessage() );  //  👈 Add this line
        throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.'));
    }
    ...
}

🏅Result

Now useful information will be populated in Magento's var/system.log:

[2021-02-19 18:30:46] report.ERROR: Notice: Undefined index: match in app/code/Mything/Elasticsearch/Plugin/SearchAdapter/Query/Builder/Match.php on line 50 [] []
[2021-02-19 18:30:46] report.ERROR: Sorry, something went wrong. You can find out more in the error log. [] []

📚Academic Reading

This error is specific to Magento sites using the Mageplaza_LayeredNavigation module.

I understand that for frontend users we would want a static & locally translated message. However it seems very silly to catch an Exception but not log or render any information about the actual Exception. To make things debuggable, this implementation needed to be changed.

What caused it (for me); your's will be different:

I encountered Mageplaza's LocalizedException when creating a plugin on afterBuild() for this class:

Magento\Elasticsearch\SearchAdapter\Query\Builder\Match

The issue was caused by a very simple error in my own plugin's afterBuild() method (for me, it was simply a Notice about a missing array key). However due to Mageplaza's try{}catch(){} block throwing a static message in a LocalizedException, I did not have the information necessary to debug the underlying issue.

Personal experience with this brand of modules

I've been involved with sites using Mageplaza modules from 2014 to 2021. Although some of their development staff is extremely talented (Uri is great), these types of best-practice missteps seem to arise semi-frequently regarding Mageplaza modules. Some of their implementations seem less-than-professional or not thoroughly finished for minor things like this and it commonly costs me hours of extra time. Some areas of their codebase remind me of when I leave a //TO-DO: comment marker in my own code to flag a better way to implement something later because I don't have time at the moment to do it right.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top