Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,27 @@ function ( $time ) use ( $cache_time ) {
$feed->set_useragent( apply_filters( 'http_headers_useragent', $set_server_agent ) );
}

$feed->init();
try {
$feed->init();
} catch ( \Throwable $e ) {
$feed_url_str = is_array( $feed_url ) ? implode( ', ', $feed_url ) : $feed_url;
$error_context = array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
);
// Only log stack trace when debugging to avoid exposing server paths.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$error_context['error_trace'] = $e->getTraceAsString();
}
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Error while parsing feed URL "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url_str, $e->getMessage() ),
$error_context
);
// Return the feed object in a degraded state
return $feed;
}

if ( ! $feed->get_type() ) {
return $feed;
Expand Down Expand Up @@ -965,7 +985,27 @@ function ( $time ) use ( $cache_time ) {

$data = wp_remote_retrieve_body( wp_safe_remote_get( $feed_url, array( 'user-agent' => $default_agent ) ) );
$cloned_feed->set_raw_data( $data );
$cloned_feed->init();
try {
$cloned_feed->init();
} catch ( \Throwable $e ) {
$feed_url_str = is_array( $feed_url ) ? implode( ', ', $feed_url ) : $feed_url;
$error_context = array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
);
// Only log stack trace when debugging to avoid exposing server paths.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$error_context['error_trace'] = $e->getTraceAsString();
}
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Error while parsing feed URL "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url_str, $e->getMessage() ),
$error_context
);
// Continue with original feed object
return $feed;
}
$error_raw = $cloned_feed->error();
if ( empty( $error_raw ) ) {
// only if using the raw url produces no errors, will we consider the new feed as good to go.
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ public function run_cron( $max = 100, $job_id = 0 ) {
);
}
do_action( 'feedzy_run_cron_extra', $job );
} catch ( Exception $e ) {
} catch ( \Throwable $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( '[Feedzy Run Cron][Post title: ' . ( ! empty( $job->post_title ) ? $job->post_title : '' ) . '] Error: ' . $e->getMessage() );
}
Expand Down
Loading