✅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.