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
Conversation
|
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: |
Test Results SummaryCommit SHA: 7ea67ef
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. |
There was a problem hiding this 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
0044eeb
to
dfefd79
Compare
|
Thanks, @psealock!
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! |
|
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. |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks, @chihsuan!
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. |
…4037) * Add rudimentary try catch for all remote endpoint spec evaluators * Changelog * Lint * More lint
* 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>
…4037) * Add rudimentary try catch for all remote endpoint spec evaluators * Changelog * Lint * More lint
* 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>
…4037) * Add rudimentary try catch for all remote endpoint spec evaluators * Changelog * Lint * More lint
* 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>
…4037) * Add rudimentary try catch for all remote endpoint spec evaluators * Changelog * Lint * More lint

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:
Testing
wp transient delete --allDisplay suggestions within WooCommerceis checked/wp-admin/admin.php?page=wc-admin&path=/setup-wizardI'm just starting my businessand continueAustralia — Australian Capital Territoryand continue