I encountered this error unexpectedly. How can I find the solution to solve it? This is where error occured
$resultPage->getLayout()->getBlock('messages')->setEscapeMessageFlag(true);
PHP Fatal error: Uncaught Error: Call to a member function setEscapeMessageFlag() on boolean in /var/www/html/magento2/vendor/magento/module-customer/Controller/Account/Edit.php:83\n Stack trace:\n
#0 /var/www/html/magento2/var/generation/Magento/Customer/Controller/Account/Edit/Interceptor.php(24): Magento\Customer\Controller\Account\Edit->execute()\n
#1 /var/www/html/magento2/vendor/magento/framework/App/Action/Action.php(102): Magento\Customer\Controller\Account\Edit\Interceptor->execute()\n
#2 /var/www/html/magento2/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))\n
#3 /var/www/html/magento2/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Customer\Controller\Account\Edit\Interceptor->___callParent('dispatch', Array)\n
#4 /var/www/html/magento2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Custome...', 'dispatch', Object(Magento\Customer\Con in /var/www/html/magento2/vendor/magento/module-customer/Controller/Account/Edit.php on line 83
1 Answer 1
This is a known Magento bug:
https://github.com/magento/magento2/issues/4127
Basically if the page lacks page.messages block, it will cause Magento 2 fail with critical error message (dev mode) or white screen of death (production mode). Usually it happens when your layout contains something like this:
<referenceBlock name="page.messages" remove="true"/>
Removing message block is not a good practice anyway, so if you absolutely need to do it, just display empty template file instead.
Explore related questions
See similar questions with these tags.