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

Add rudimentary try catch for all remote endpoint spec evaluators #44037

Merged
merged 4 commits into from Jan 25, 2024

Conversation

ilyasfoo
Copy link
Contributor

@ilyasfoo ilyasfoo commented Jan 24, 2024

Changes proposed in this Pull Request:

In light of a recent fatal due to faulty rule in PaymentGatewaySuggestions, this PR aims to add rudimentary and broad try-catch in order to prevent future fatals.

How to test the changes in this Pull Request:

In order to simulate errors either:

  1. Cherry-pick the commit 52f8fa8 from this branch
  2. Or manually set the following APIs

Testing

  1. In your environment, use PHP 8.1+
  2. If using an existing site, clear transients by running wp transient delete --all
  3. Ensure WooCommerce > Settings > Advanced > Woo.com > Display suggestions within WooCommerce is checked
  4. Go to Setup Wizard, /wp-admin/admin.php?page=wc-admin&path=/setup-wizard
  5. Click continue
  6. Select I'm just starting my business and continue
  7. Select Australia — Australian Capital Territory and continue
  8. Skip plugin installation
  9. Observe no fatal when loading homescreen
  10. Go to Tools > WCA Test Helper > Tools > Run wc_admin_daily job
  11. Ensure the job is run successfully

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jan 24, 2024
@ilyasfoo ilyasfoo changed the title Add rudimentary try catch for all remote endpoint spec evaluators Add rudimentary try catch for all remote endpoint spec evaluators (target 8.5 release) Jan 24, 2024
@ilyasfoo ilyasfoo requested review from a team, chihsuan and moon0326 January 24, 2024 14:35
Copy link
Contributor

Hi @chihsuan, @moon0326, @woocommerce/ghidorah

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

github-actions bot commented Jan 24, 2024

Test Results Summary

Commit SHA: 7ea67ef

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests2750021029610m 1s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

Copy link
Contributor

@psealock psealock left a comment

Choose a reason for hiding this comment

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

No fatals occur and the wc admin job runs successfully.

I am seeing the error Warning: strpos() expects parameter 1 to be string, array given in... at the top of the page, but I believe this is to be expected.

I also confirmed there are no unchecked instances of evaluate in the codebase for RIN evaluation.

The only objection I have is this PR should target trunk and ultimately cherry-picked to release/8.5

@psealock psealock changed the base branch from release/8.5 to trunk January 25, 2024 01:31
@psealock psealock changed the base branch from trunk to release/8.5 January 25, 2024 01:32
@ilyasfoo ilyasfoo force-pushed the fix/8.5/rudimentary-trycatch-remote-apis branch from 0044eeb to dfefd79 Compare January 25, 2024 02:05
@ilyasfoo ilyasfoo changed the base branch from release/8.5 to trunk January 25, 2024 02:05
@ilyasfoo ilyasfoo closed this Jan 25, 2024
@ilyasfoo ilyasfoo reopened this Jan 25, 2024
@ilyasfoo
Copy link
Contributor Author

Thanks, @psealock!

I am seeing the error Warning: strpos() expects parameter 1 to be string, array given in... at the top of the page, but I believe this is to be expected.

I wasn't able to get this, do you have the full warning message?

Also, can you confirm if you're using PHP 8.1+? I forgot to include that in the testing instructions.

I've also updated the branch and fixed lint, please take another look!

@ilyasfoo ilyasfoo changed the title Add rudimentary try catch for all remote endpoint spec evaluators (target 8.5 release) Add rudimentary try catch for all remote endpoint spec evaluators Jan 25, 2024
@adrianduffell
Copy link
Contributor

Thanks for your work on this @ilyasfoo ❤️

This is just a nitpick: I'd like to see generic exception catch-alls handled higher up in the call stack, as there is still the potential for exceptions to be raised in other lines of code elsewhere (in any line of code really). I could see perhaps having a single catch-all within each feature (like the remote inbox), that wraps all code that gets executed within it.

For deeper level code like this, I think it's better to catch only specific exceptions that could be reasonably anticipated and handling those appropriately, e.g. with logging or a warning to the user, so that problems are more visible when they arise.

@ilyasfoo
Copy link
Contributor Author

ilyasfoo commented Jan 25, 2024

This is just a nitpick: I'd like to see generic exception catch-alls handled higher up in the call stack, as there is still the potential for exceptions to be raised in other lines of code elsewhere (in any line of code really). I could see perhaps having a single catch-all within each feature (like the remote inbox), that wraps all code that gets executed within it.

@adrianduffell Good suggestion, but I believe the try-catch blocks added here are at the highest level we can get. For example, PaymentGatewaySuggestion is called with a static function, thus it can be called from anywhere in the code.

Also, the benefit with adding the try-catch blocks in each individual evaluation will limit evaluation failures to individual spec, instead of throwing out the entire data.

I generally agree that we may benefit from having multiple try-catch levels, where the highest is at feature-level, and logs error. However, I believe that requires a lot more changes, and we should focus on minimal changes with the PR since we also need to cherry-pick these changes into previous versions.

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Looks good and confirmed no errors are present in a PHP 8.2 Site. 👍

However, I noticed the payment task doesn't display properly. But I agree we can create a follow-up issue for further changes.

Screenshot 2024-01-25 at 18 35 04

@ilyasfoo
Copy link
Contributor Author

ilyasfoo commented Jan 25, 2024

Thanks, @chihsuan!

However, I noticed the payment task doesn't display properly. But I agree we can create a follow-up issue for further changes.

This is expected when you're using the faulty spec since there is only 1 spec defined, and it will result in an empty list. Still, I agree that we should handle payments task better when there's no suggestions available.

@ilyasfoo ilyasfoo added this to the 8.6.0 milestone Jan 25, 2024
@github-actions github-actions bot removed this from the 8.6.0 milestone Jan 25, 2024
@ilyasfoo ilyasfoo merged commit 2c283d7 into trunk Jan 25, 2024
36 checks passed
@ilyasfoo ilyasfoo deleted the fix/8.5/rudimentary-trycatch-remote-apis branch January 25, 2024 10:58
@github-actions github-actions bot added this to the 8.7.0 milestone Jan 25, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jan 25, 2024
@nigeljamesstevenson nigeljamesstevenson modified the milestones: 8.7.0, 8.5.0 Jan 25, 2024
github-actions bot pushed a commit that referenced this pull request Jan 25, 2024
…4037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint
nigeljamesstevenson pushed a commit that referenced this pull request Jan 25, 2024
* Add rudimentary try catch for all remote endpoint spec evaluators (#44037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint

* Prep for cherry pick 44037

---------

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
Co-authored-by: WooCommerce Bot <no-reply@woo.com>
@veljkho veljkho added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Jan 26, 2024
@nigeljamesstevenson nigeljamesstevenson modified the milestones: 8.5.0, 8.6.0 Jan 26, 2024
github-actions bot pushed a commit that referenced this pull request Jan 26, 2024
…4037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint
@nigeljamesstevenson nigeljamesstevenson modified the milestones: 8.6.0, 8.7.0 Jan 26, 2024
nigeljamesstevenson pushed a commit that referenced this pull request Jan 26, 2024
* Add rudimentary try catch for all remote endpoint spec evaluators (#44037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint

* Prep for cherry pick 44037

---------

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
Co-authored-by: WooCommerce Bot <no-reply@woo.com>
github-actions bot pushed a commit that referenced this pull request Jan 29, 2024
…4037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint
nigeljamesstevenson pushed a commit that referenced this pull request Jan 29, 2024
* Add rudimentary try catch for all remote endpoint spec evaluators (#44037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint

* Prep for cherry pick 44037

---------

Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
Co-authored-by: WooCommerce Bot <no-reply@woo.com>
@nigeljamesstevenson nigeljamesstevenson added the needs: internal testing Indicates if the PR requires further testing conducted by Solaris label Feb 5, 2024
@alopezari alopezari added the fix release: 8.5.2 Temporary label for fix release metrics retrieval label Feb 6, 2024
@alopezari alopezari modified the milestones: 8.6.0, 8.5.0 Feb 7, 2024
github-actions bot pushed a commit that referenced this pull request Feb 7, 2024
…4037)

* Add rudimentary try catch for all remote endpoint spec evaluators

* Changelog

* Lint

* More lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix release: 8.5.2 Temporary label for fix release metrics retrieval needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants