Description
This issue is automatically created based on existing pull request: #38160: Improved error handling when rendering templates, so no html leaks wh…
…en a php error occurs.
Description (*)
We noticed that Magento only catches exceptions and not php errors when rendering templates.
When it catches exceptions, the rendered output so-far gets discarded using the ob_end_clean
php function. This didn't happen for PHP errors yet. If we change the try catch to catch a Throwable
instead of an Exception
this gets fixed.
This was found while writing a little module to run over all the cms pages of a very content-heavy webshop and we are trying to render those in the backoffice so we can display which pages have errors, so the merchant can see at a glance which cms content is broken. We noticed that when a fatal php error happened while rendering a frontend cms page, it outputted part of the html before the error to the browser already, this doesn't happen if an exception gets thrown.
So we align this behavior in this PR.
This builds further on #25250 where similar changes got done.
Related Pull Requests
N/A
Fixed Issues (if relevant)
N/A
Manual testing scenarios (*)
- Simulate both an exception and a PHP error in the frontend
- An easy way is to temporarily change the template file
app/code/Magento/Search/view/frontend/templates/form.mini.phtml
- And either put the following at the end of the file (it's important it's at the end, not at the beginning!)
- first time:
<?php throw new \Exception('test');
- second time:
<?php $quickSearchUrl->doSomethingThatDoesnExist();
- first time:
- An easy way is to temporarily change the template file
- Validate the results on the frontend in both cases, try it both in
production
anddeveloper
mode and see the differences and if they make sense or not - Validate that a developer can still find useful info about the exception/error in the log files
In the case of a php error in production mode, this is the difference in the browser.
Before this PR:
Questions or comments
I couldn't find unit tests for this part of core Magento, so I have nothing to base new automated testing on, so I'll just skip this otherwise it's going to take me too long to figure out how to write tests for this. So if somebody could help out with this part, that would be appreciated!
Contribution checklist (*)
- 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)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status