Fatal error in Email Reporting when searchanalytics-batch returns WP_Error
-
Environment
- Site Kit version: 1.182.0
- WordPress: 6.9.4
- PHP: 8.3.32
Description
We are seeing a weekly fatal error when the Site Kit Email Reporting cron job runs.
Search Console is configured correctly and works normally in the Site Kit dashboard. Analytics and the other connected services also work without any issues.
The error only occurs during the weekly Email Reporting task.
Fatal error
Uncaught Error: Cannot use object of type WP_Error as array Report_Request_Assembler.php:182Stack trace starts with:
Google\Site_Kit\Modules\Search_Console\Email_Reporting\Report_Request_Assembler->map_responses() Google\Site_Kit\Core\Email_Reporting\Email_Reporting_Data_Requests->collect_search_console_payloads()Code analysis
Email_Reporting_Data_Requests::collect_search_console_payloads()contains:$response = $module->set_data( 'searchanalytics-batch', array( 'requests' => $requests, ) ); return $request_assembler->map_responses( $response, $request_map );According to the PHPDoc, this method may return:
@return array|WP_ErrorHowever,
map_responses()assumes$responsesis always an array and immediately accesses:$responses[ $identifier ]If
$module->set_data()returns aWP_Error, PHP throws:Cannot use object of type WP_Error as arrayIt appears that either:
collect_search_console_payloads()should checkis_wp_error( $response )before callingmap_responses(), ormap_responses()should handle aWP_Errorargument before treating it as an array.
Additional information
- Search Console data loads correctly in the dashboard.
- Site Health reports all required scopes and permissions.
- The issue appears when the Search Console module is managed by another connected user.
searchanalytics-batchreturns aWP_Errorwithmissing_required_scopes(403), butcollect_search_console_payloads()passes theWP_Errordirectly tomap_responses(), causing a fatal error instead of handling the authorization problem gracefully.
Please let me know if additional debug information or logs would be helpful.
You must be logged in to reply to this topic.