Skip to content

Clarify WP_Error handling safety for rest_post_dispatch type hint#76346

Closed
Copilot wants to merge 1 commit intorefactor/connectors-rest-level-validation-maskingfrom
copilot/sub-pr-76327
Closed

Clarify WP_Error handling safety for rest_post_dispatch type hint#76346
Copilot wants to merge 1 commit intorefactor/connectors-rest-level-validation-maskingfrom
copilot/sub-pr-76327

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

A review comment on #76327 suggested loosening the WP_REST_Response $response type hint on _gutenberg_connectors_rest_settings_dispatch, claiming rest_post_dispatch could receive a WP_Error and cause a fatal TypeError. This PR investigates and responds to that concern.

Finding

The concern is unfounded. WordPress core's serve_request explicitly converts any WP_Error to WP_REST_Response via error_to_response() before invoking rest_post_dispatch:

// ...then convert WP_Error across.
if ( is_wp_error( $result ) ) {
    $result = $this->error_to_response( $result );
}
$result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request );

The WP_REST_Response $response type hint is accurate and safe — no code changes are required.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Clarify API key validation handling in REST dispatch Clarify WP_Error handling safety for rest_post_dispatch type hint Mar 10, 2026
@gziolo gziolo closed this Mar 10, 2026
@gziolo gziolo deleted the copilot/sub-pr-76327 branch March 10, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants