Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add error handling for Automattic\WooCommerceBlocks\RestApi::get_routes_from_namespace(). #4683

Closed
nerrad opened this issue Sep 3, 2021 · 1 comment · Fixed by #5319
Closed
Assignees
Labels
focus: rest api Work impacting REST api routes. type: bug The issue/PR concerns a confirmed bug. type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team.

Comments

@nerrad
Copy link
Contributor

nerrad commented Sep 3, 2021

In various places in WordPress.org forums and at least one instance in our repo (see #4647) I've noticed reports of this error show up:

Fatal error: Uncaught Error: Call to undefined method WP_Error::get_data()

The callstack for that usually points to this line:

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/src/RestApi.php#L64

While at least one report (#4647) is triggered in the context of Elementor being used on the site, I suspect the underlying cause is that the function in question gets called before the WP_REST_Server is setup and/or before the namespaced being called is registered.

At a minimum, we should add some WP_Error handling in this method and return null if it's present. This will prevent the fatal error from happening in those contexts and remove it from being a potential red herring for the real issue that may be present in this scenarios.

@nerrad nerrad added focus: rest api Work impacting REST api routes. type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team. type: bug The issue/PR concerns a confirmed bug. labels Sep 3, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2021

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.

Internal: After 10 days with no activity this issue will be automatically be closed.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Nov 3, 2021
@nerrad nerrad removed the status: stale Stale issues and PRs have had no updates for 60 days. label Nov 3, 2021
@mikejolley mikejolley self-assigned this Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: rest api Work impacting REST api routes. type: bug The issue/PR concerns a confirmed bug. type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants