Skip to content

Addressing PR comments#1196

Closed
Claude wants to merge 3 commits intomasterfrom
claude/catch-throwable-around-simplepie-init
Closed

Addressing PR comments#1196
Claude wants to merge 3 commits intomasterfrom
claude/catch-throwable-around-simplepie-init

Conversation

@Claude
Copy link
Copy Markdown

@Claude Claude AI commented Mar 23, 2026

Original prompt

This section details on the original issue you should resolve

<issue_title>Catch Throwable (not Exception) around SimplePie init and import cron</issue_title>
<issue_description>## Problem

SimplePie::init() can throw fatal errors (especially TypeError on PHP 8+) that crash the entire import cron cycle. The current cron error handler catches Exception but not Error — and PHP 8+ TypeError extends Error, not Exception. Additionally, the cloned feed fallback path calls $cloned_feed->init() without any error handling.

Solution

admin-abstract.php:

  • Wrap $feed->init() in try/catch(\Throwable) with logging and graceful return
  • Wrap $cloned_feed->init() in the same pattern (SSL retry fallback path)

import.php:

  • Change catch (Exception $e) to catch (\Throwable $e) in run_cron()

Files Affected

  • includes/abstract/feedzy-rss-feeds-admin-abstract.php
  • includes/admin/feedzy-rss-feeds-import.php

Acceptance Criteria

  • SimplePie TypeError on PHP 8+ does not crash the cron cycle
  • Failed feed init is logged with feed URL and stack trace
  • Feed object is still returned (degraded) after init failure
  • Other import jobs continue running even if one feed crashes
  • Cloned feed fallback path handles errors gracefully

Priority: High — prevents cron cycle crashes on PHP 8+
Regression risk: Isolated — try/catch is purely additive</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

- Wrap $feed->init() in try/catch(\Throwable) in admin-abstract.php
- Wrap $cloned_feed->init() in try/catch(\Throwable) in admin-abstract.php
- Change catch(Exception) to catch(\Throwable) in import.php run_cron()
- Log fatal errors with feed URL and stack trace
- Return feed object in degraded state on init failure
- Prevent PHP 8+ TypeError from crashing cron cycle

Co-authored-by: ineagu <1849868+ineagu@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Codeinwp/feedzy-rss-feeds/sessions/37a03833-a2eb-4073-8144-325ec6698a07
@Claude Claude AI changed the title [WIP] Catch Throwable around SimplePie init and import cron Catch Throwable around SimplePie init to prevent PHP 8+ TypeError crashes Mar 23, 2026
@Claude Claude AI requested a review from ineagu March 23, 2026 15:04
@ineagu ineagu requested a review from Copilot March 23, 2026 15:10
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Mar 23, 2026

🌍 i18n String Review Report

📊 Summary

Category Count
➕ Added 2
➖ Removed 0
🔄 Changed 0
Total 2
➕ Added Strings (2) - Click to expand
String Location Words Suggested Match
Fatal error during SimplePie init for feed "%1$... includes/abstract/feedzy-r... 9 Error while parsing feed URL "%1$s": %2$s
Fatal error during SimplePie init (raw data fa... includes/abstract/feedzy-r... 12 Error while parsing feed URL "%1$s": %2$s
Total 21

1 similar comment
@pirate-bot
Copy link
Copy Markdown
Contributor

🌍 i18n String Review Report

📊 Summary

Category Count
➕ Added 2
➖ Removed 0
🔄 Changed 0
Total 2
➕ Added Strings (2) - Click to expand
String Location Words Suggested Match
Fatal error during SimplePie init for feed "%1$... includes/abstract/feedzy-r... 9 Error while parsing feed URL "%1$s": %2$s
Fatal error during SimplePie init (raw data fa... includes/abstract/feedzy-r... 12 Error while parsing feed URL "%1$s": %2$s
Total 21

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Feedzy’s feed import pipeline against PHP 8+ TypeError/Error crashes by catching \Throwable around SimplePie::init() and within the cron job execution loop, ensuring a single failing feed/job doesn’t abort the entire import run.

Changes:

  • Wrap SimplePie::init() calls in try/catch (\Throwable) (including the raw-data fallback path) with error logging and graceful degradation.
  • Update import cron runner to catch \Throwable (not just Exception) so PHP 8+ errors don’t crash the cron cycle.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
includes/abstract/feedzy-rss-feeds-admin-abstract.php Adds \Throwable guards and logging around SimplePie initialization (primary + fallback).
includes/admin/feedzy-rss-feeds-import.php Broadens cron error handler from Exception to \Throwable to prevent import-cycle crashes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +926 to +928
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this sprintf() message, $feed_url can be an array (multi-feed), which will trigger an “Array to string conversion” warning and log an unhelpful value. Consider formatting it to a string first (e.g., implode(', ', $feed_url) when it’s an array) before interpolating into the message.

Suggested change
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
$feed_url_str = is_array( $feed_url ) ? implode( ', ', $feed_url ) : $feed_url;
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url_str, $e->getMessage() ),

Copilot uses AI. Check for mistakes.
Comment on lines +926 to +934
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
'error_trace' => $e->getTraceAsString(),
)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full Throwable stack trace into uploads/feedzy-logs can expose server paths and other sensitive details if the log directory is ever web-accessible (e.g., non-Apache setups that ignore .htaccess). Consider gating error_trace behind WP_DEBUG / a plugin debug setting and/or truncating it to a safe length.

Suggested change
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
'error_trace' => $e->getTraceAsString(),
)
$error_context = array(
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
);
// Only log the full error trace when debugging is enabled, and truncate it to a safe length.
if ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'FEEDZY_DEBUG' ) && FEEDZY_DEBUG ) ) {
$error_trace = $e->getTraceAsString();
// Limit the length of the logged trace to reduce potential information exposure.
$error_context['error_trace'] = substr( $error_trace, 0, 5000 );
}
Feedzy_Rss_Feeds_Log::error(
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
$error_context

Copilot uses AI. Check for mistakes.
Comment on lines +987 to +989
// translators: %1$s is the feed URL, %2$s is the error message.
sprintf( __( 'Fatal error during SimplePie init (raw data fallback) for feed "%1$s": %2$s', 'feedzy-rss-feeds' ), $feed_url, $e->getMessage() ),
array(
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: $feed_url may be an array here, so interpolating it with %s can raise an “Array to string conversion” warning. Format $feed_url to a readable string before using it in the translated message.

Copilot uses AI. Check for mistakes.
Comment on lines +990 to +994
'feed_url' => $feed_url,
'cache' => $cache,
'sc' => $sc,
'error_trace' => $e->getTraceAsString(),
)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as the earlier catch: error_trace will persist full stack traces to the JSONL log file under uploads. Consider restricting/truncating stack traces to reduce sensitive data exposure and log growth.

Copilot uses AI. Check for mistakes.
@ineagu
Copy link
Copy Markdown
Contributor

ineagu commented Mar 23, 2026

@claude[agent] can you fix the review items? and avoid introducing new strings

- Convert array feed_url to string before sprintf to avoid "Array to string conversion" warning
- Use existing i18n string 'Error while parsing feed URL' instead of new strings
- Gate error_trace logging behind WP_DEBUG to avoid exposing server paths
- Apply same fixes to both try/catch blocks (main and cloned feed fallback)

Co-authored-by: ineagu <1849868+ineagu@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Codeinwp/feedzy-rss-feeds/sessions/64940696-8245-4120-a016-b99ce52ecd93
@Claude
Copy link
Copy Markdown
Author

Claude AI commented Mar 23, 2026

@claude[agent] can you fix the review items? and avoid introducing new strings

Fixed in a6ce3c0:

  • Array feed_url converted to string before sprintf to avoid warnings
  • Stack traces now only logged when WP_DEBUG is enabled
  • Reused existing i18n string "Error while parsing feed URL" (removed 2 new strings)

@Claude Claude AI changed the title Catch Throwable around SimplePie init to prevent PHP 8+ TypeError crashes Addressing PR comments Mar 23, 2026
@ineagu ineagu requested a review from Copilot March 23, 2026 16:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ineagu ineagu closed this Mar 24, 2026
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.

Catch Throwable (not Exception) around SimplePie init and import cron

4 participants