Fix: auto update check error should not fail the running command#6345
Fix: auto update check error should not fail the running command#6345swissspidy with Copilot wants to merge 12 commits into
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Use WP_CLI::runcommand() with exit_error=>false and return=>'all' in Runner::auto_check_update() so that HTTP/network errors during the background update check are silently captured (logged at debug level) instead of propagating and failing the user's command. Closes #6344 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Fixed 1 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
|
I dug further into More importantly, this code is meant to fail open. If the result contract ever isn’t met, the direct property accesses emit warnings (or throw through an installed error handler) and can once again interfere with the user’s command. Please keep defensive validation here, and validate the full result rather than only calling This still won’t protect against |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
php/WP_CLI/Runner.php (1)
2728-2733: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winValidate the
runcommand()result before readingstdout.is_object()doesn't guaranteereturn_code,stdout, andstderrexist or have the expected types, so malformed results can still emit notices and a non-numericstdoutcan fall through to the update prompt. Reject missing fields and cast a numeric count before continuing.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@php/WP_CLI/Runner.php` around lines 2728 - 2733, Validate the result in the background update check before accessing its fields: require an object with valid return_code, stderr, and stdout values, and retain the existing debug-and-return failure path for malformed results. Convert stdout to a numeric count before assigning it to $count so non-numeric output cannot reach the update prompt.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@php/WP_CLI/Runner.php`:
- Around line 2728-2733: Validate the result in the background update check
before accessing its fields: require an object with valid return_code, stderr,
and stdout values, and retain the existing debug-and-return failure path for
malformed results. Convert stdout to a numeric count before assigning it to
$count so non-numeric output cannot reach the update prompt.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f589edd8-9c12-4a9e-b19a-0bd9eaf86df5
📒 Files selected for processing (1)
php/WP_CLI/Runner.php
This comment was marked as resolved.
This comment was marked as resolved.
@schlessera Mind double checking? I don't see how it could never return in those cases. The return values seem pretty clear, and there is |
When the background update check hits a network/HTTP error (e.g. 401, 403 rate-limit),
CLI_Command::get_updates()callsWP_CLI::error(), which exits the process — silently killing whatever command the user actually ran.Changes
Runner::auto_check_update(): Replace the bareob_start() / WP_CLI::run_command()pattern withWP_CLI::runcommand()usingexit_error => falseandreturn => 'all'exit_error => falsesets$capture_exit = truesoWP_CLI::error()throwsExitExceptioninstead of callingexit()return => 'all'swaps in anExecutionlogger that captures stdout/stderr in memory — the error message is never printed to the terminalWP_CLI::debug()message is emitted (visible with--debug) and the check silently returns without affecting the user's commandSummary by CodeRabbit