Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling for issues during bulk attribute update #1434

Merged
merged 3 commits into from May 30, 2022
Merged

Better error handling for issues during bulk attribute update #1434

merged 3 commits into from May 30, 2022

Conversation

woutersamaey
Copy link
Contributor

If something goes wrong during mass product attribute update, the admin gets a generic message and there is no error in the log, making it harder to debug this issue.

@github-actions github-actions bot added the Component: Adminhtml Relates to Mage_Adminhtml label Jan 29, 2021
kiatng
kiatng previously approved these changes Jan 30, 2021
Copy link
Contributor

@jouriy jouriy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just would suggest to keep Exception handling for backward compatibility, i.e.

        catch (Throwable $e) {
            Mage::logException($e);
            $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.'));
        } catch (Exception $e) {
            $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.'));

@woutersamaey
Copy link
Contributor Author

@jouriy your suggestion does not make much sense. Magento 1 was written at a time when Exception was the most generic thing to catch. Since PHP7 this has become Throwable, so I’m pretty sure this is what was originally meant.
Things like TypeError did not exist at the time, but can now be a regular issue if you work in strict mode. This is why (IMHO) all mentions of Exception should be replaced with Throwable.

@jouriy
Copy link
Contributor

jouriy commented Jan 30, 2021

Thank you for the details. The reason why I suggested it was my impression that 1.9.4.x branch is supposed to be backward compatible with Magento 1.9.x (and drop-in replacement) which is still mostly on PHP 5.6, so removing Exception handling means no any error reporting for 5.x.

This is why (IMHO) all mentions of Exception should be replaced with Throwable.

Should not we create a new PR than to bring better error handing for all cases?

@woutersamaey
Copy link
Contributor Author

I updated the code as per @colinmollenhour suggestion.

@woutersamaey
Copy link
Contributor Author

woutersamaey commented Feb 2, 2021

@jouriy running on PHP5.6 is a security risk, so I'm trying my best to modernize up to PHP7 without going overboard.
I'm contributing small things, as they affect my work.

Replacing all Exceptions with Throwables is now suggested in #1442

@colinmollenhour
Copy link
Member

Ahh I just remembered that addException already logs the exception so this will double-log it.

@woutersamaey
Copy link
Contributor Author

woutersamaey commented Feb 2, 2021

@colinmollenhour I don’t follow. What are you trying to say?

Okay, I think you are referring to \Mage_Core_Model_Session_Abstract::addException(), except this isn't quite the same. This does log the exception, but using Mage::log() and a custom message. Not using Mage::logException().

For me this isn't acceptable because we use special exception tracking and for that to work everything needs to go through Mage::logException() which is what Magento normally does.

I've changed my code for a better solution that does not log twice anymore.

@woutersamaey
Copy link
Contributor Author

I also created #1443 where I change the superfluous handing of the Exception in Mage_Core_Model_Session_Abstract::addException()

Magento seams to have forgotten about it's own Mage::logException(). Why they would ever format their own string and pass it to Mage::log() is beyond me.

@woutersamaey
Copy link
Contributor Author

Should I also move this to branch 20.0 ?

@fballiano fballiano dismissed colinmollenhour’s stale review May 29, 2022 17:23

All requested changes have been implemented by the author

@fballiano fballiano merged commit 0775715 into OpenMage:1.9.4.x May 30, 2022
@github-actions
Copy link

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  +5  5 ✔️ +3  2 💤 +2  0 ❌ ±0 

Results for commit 0775715. ± Comparison against base commit eaf4354.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Adminhtml Relates to Mage_Adminhtml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants