Skip to content

Stop catching exceptions and destroying them #30241

Open
@oliverde8

Description

@oliverde8

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.

Cause:
https://github.com/magento/magento2/blob/2.4.0/app/code/Magento/GiftMessage/Model/GiftMessageManager.php#L87

Why are the exceptions caught, in the example case the method calling the add function has a try-catch as well.

Proposed solution

  1. Don't try catch \Exception if possible
  2. When catching an \Exception at least log it
  3. 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
show_error
and try to imitate an exception

Preconditions

Magento 2.4-develop
Allow Gift Messages is enabled

Steps to reproduce

  1. Add a throw new CouldNotSaveException(__("Show custom error.")); code to the /app/code/Magento/GiftMessage/Model/GiftMessageManager.php file
  2. Add a Product to Cart
  3. Type long name with different characters into From and To fields under Gift Options
  4. Update

Expected Result

An exception message in logs

Actual Result

No exception message in logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ExceptionComponent: GiftMessageIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: ready for confirmationPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReported on 2.4.0Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions