woocommerce / woocommerce-paypal-payments

https://wordpress.org/plugins/woocommerce-paypal-payments/
GNU General Public License v2.0
62 stars 47 forks source link

Uncaught AssertionError being thrown (1723) #1392

Closed wavvves closed 1 year ago

wavvves commented 1 year ago

Describe the Bug

While testing WooCommerce Paypal Payments integration with WooCommerce-Blocks I noticed a critical being logged. Root cause seems to have assert() being used in the open, which can throw an exception. Either wrapping and handling that or, preferably, data check and remove it if the required boolean result can be achieved without it. Line reference

To Reproduce

A bit hard to reproduce, finding exact steps revealed a hard task. Seems to occur while configuring it to work with blocks while refreshing cart/checkout to monitor changes.

Screenshots

n/a

Expected Behavior

No critical errors being logged.

Actual Behavior

2023-05-18T20:36:27+00:00 CRITICAL Uncaught AssertionError: assert($smart_button instanceof SmartButton) in /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-blocks/src/BlocksModule.php:71
Stack trace:
#0 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-blocks/src/BlocksModule.php(71): assert(false, 'assert($smart_b...')
#1 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Schemas/ExtendSchema.php(292): WooCommerce\PayPalCommerce\Blocks\BlocksModule->WooCommerce\PayPalCommerce\Blocks\{closure}()
#2 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Schemas/V1/CartSchema.php(383): Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema->get_payment_requirements()
#3 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Routes/V1/Cart.php(50): Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema->get_item_response(Object(WC_Cart))
#4 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Routes/V1/AbstractRoute.php(126): Automattic\WooCommerce\StoreApi\Routes\V1\Cart->get_route_response(Object(WP_REST_Request))
#5 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Routes/V1/AbstractCartRoute.php(109): Automattic\WooCommerce\StoreApi\Routes\V1\AbstractRoute->get_response_by_request_method(Object(WP_REST_Request))
#6 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/rest-api/class-wp-rest-server.php(1181): Automattic\WooCommerce\StoreApi\Routes\V1\AbstractCartRoute->get_response(Object(WP_REST_Request))
#7 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/rest-api/class-wp-rest-server.php(1028): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wc/store/v1/ca...', Array, NULL)
#8 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/rest-api/class-wp-rest-server.php(442): WP_REST_Server->dispatch(Object(WP_REST_Request))
#9 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/rest-api.php(410): WP_REST_Server->serve_request('/wc/store/v1/ca...')
#10 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/class-wp-hook.php(308): rest_api_loaded(Object(WP))
#11 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#12 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#13 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/class-wp.php(399): do_action_ref_array('parse_request', Array)
#14 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/class-wp.php(780): WP->parse_request('')
#15 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-includes/functions.php(1334): WP->main('')
#16 /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-blog-header.php(16): wp()
#17 /srv/users/user8f251bb6/apps/user8f251bb6/public/index.php(17): require('/srv/users/user...')
#18 {main}
  thrown in /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-blocks/src/BlocksModule.php on line 71

Environment

Additional Details

System status ### WordPress Environment ### WordPress address (URL): https://bumpy-shad.jurassic.ninja Site address (URL): https://bumpy-shad.jurassic.ninja WC Version: 7.7.0 REST API Version: ✔ 7.7.0 WC Blocks Version: ✔ 10.2.0 Action Scheduler Version: ✔ 3.5.4 Log Directory Writable: ✔ WP Version: 6.2.1 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: ✔ WP Cron: ✔ Language: en_US External object cache: – ### Server Environment ### Server Info: Apache/2.4.57 (Unix) OpenSSL/1.0.2g PHP Version: 8.0.28 PHP Post Max Size: 1 GB PHP Time Limit: 30 PHP Max Input Vars: 5000 cURL Version: 7.47.0 OpenSSL/1.0.2g SUHOSIN Installed: – MySQL Version: 5.7.33-0ubuntu0.16.04.1-log Max Upload Size: 512 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 7.7.0 WC Database Prefix: wp_ Total Database Size: 6.45MB Database Data Size: 4.84MB Database Index Size: 1.61MB wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.05MB + Index: 0.09MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_options: Data: 3.48MB + Index: 0.06MB + Engine InnoDB wp_postmeta: Data: 0.23MB + Index: 0.17MB + Engine InnoDB wp_posts: Data: 0.17MB + Index: 0.06MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB ### Post Type Counts ### attachment: 69 nav_menu_item: 102 page: 22 post: 39 product: 18 product_variation: 7 revision: 2 shop_order: 2 wp_global_styles: 1 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ❌Error messages should not be shown to visitors. ### Active Plugins (5) ### Companion Plugin: by Osk – 1.29 WooCommerce Blocks: by Automattic – 10.2.0 WooCommerce PayPal Payments - Enable Block Buttons: by WooCommerce – 1.0.0 WooCommerce PayPal Payments: by WooCommerce – 2.0.5-rc1 WooCommerce: by Automattic – 7.7.0 ### Inactive Plugins (0) ### ### Settings ### API Enabled: – Force SSL: – Currency: EUR (€) Currency Position: right_space Thousand Separator: Decimal Separator: , Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – Enforce Approved Product Download Directories: ✔ HPOS feature screen enabled: – HPOS feature enabled: – Order datastore: WC_Order_Data_Store_CPT HPOS data sync enabled: – ### WC Pages ### Shop base: #1364 - /shop/ Cart: #1365 - /cart/ Checkout: #1366 - /checkout/ My account: #1367 - /my-account/ Terms and conditions: ❌ Page not set ### Theme ### Name: Storefront Version: 4.2.0 Author URL: https://woocommerce.com/ Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔ ### Templates ### Overrides: /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/templates/notices/error.php /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/templates/notices/notice.php /srv/users/user8f251bb6/apps/user8f251bb6/public/wp-content/plugins/woo-gutenberg-products-block/templates/notices/success.php ### WooCommerce PayPal Payments ### Onboarded: ✔ Shop country code: PT WooCommerce currency supported: ✔ Advanced Card Processing available in country: – Pay Later messaging available in country: – Webhook status: – Vault enabled: ✔ Logging enabled: ✔ Reference Transactions: – Used PayPal Checkout plugin: – Tracking enabled: ✔ ### Admin ### Enabled Features: activity-panels analytics coupons customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page Disabled Features: product-block-editor minified-js new-product-management-experience product-variation-management settings Daily Cron: ✔ Next scheduled: 2023-05-19 15:09:36 +00:00 Options: ✔ Notes: 68 Onboarding: completed ### Action Scheduler ### Complete: 51 Oldest: 2023-05-18 15:09:47 +0000 Newest: 2023-05-19 15:01:35 +0000 Failed: 2 Oldest: 2023-05-18 15:12:46 +0000 Newest: 2023-05-18 15:19:00 +0000 Pending: 1 Oldest: 2023-05-19 15:09:47 +0000 Newest: 2023-05-19 15:09:47 +0000 ### Status report information ### Generated at: 2023-05-19 15:03:47 +00:00
ralucaStan commented 1 year ago

Thank you for testing @wavvves. Could you update the ticket to reflect: What piece of code on the WC Blocks side is triggering this AssertionError? What should we modify on our end? Thank you

wavvves commented 1 year ago

Thank you for testing @wavvves. Could you update the ticket to reflect: What piece of code on the WC Blocks side is triggering this AssertionError? What should we modify on our end? Thank you

I don't think we need to modify anything from our end, it is just a function that may throw an error being used without error handling. Furthermore, I don't really think it is needed as it is outputting a boolean that can probably be obtained without resorting to that function. I updated the description with the exact spot where it is being called.

ralucaStan commented 1 year ago

My bad @wavvves. I thought this issue was opened on https://github.com/woocommerce/woocommerce-blocks and couldn't understand what we could do on the Blocks side to fix it.

InpsydeNiklas commented 1 year ago

Thanks for testing and for the feedback! This was addressed in #1403