Description
Summary (*)
Magento catches very often \Exception and then does nothing with it. No logs nothing.
This means when such an error happens everyone thinks all is well, but in reality, hell might be breaking loose.
Examples (*)
Gift Messages:
If in the checkout your gift can't be saved due an error (for example sender name to long); the interface updates, the user thinks all is well, there are no error logs but the gift message is ignored.
Why are the exceptions caught, in the example case the method calling the add function has a try-catch as well.
Proposed solution
- Don't try catch \Exception if possible
- When catching an \Exception at least log it
- When catching an exception and creating a new one, add it to it's parents.
How hard is it to handle an exception properly It's not done properly in so many places.
We are miserable since magento2 came out; hating our profession. Can't we get these small things fixed?
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
Additional info
One way to reproduce the issue is to add a throw new CouldNotSaveException(__("Show custom error."));
code to the /app/code/Magento/GiftMessage/Model/GiftMessageManager.php file
and try to imitate an exception
Preconditions
Magento 2.4-develop
Allow Gift Messages is enabled
Steps to reproduce
- Add a
throw new CouldNotSaveException(__("Show custom error."));
code to the /app/code/Magento/GiftMessage/Model/GiftMessageManager.php file - Add a Product to Cart
- Type long name with different characters into From and To fields under Gift Options
- Update
Expected Result
An exception message in logs
Actual Result
No exception message in logs