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 3 commits into
Conversation
📝 WalkthroughWalkthroughThe auto-update check now handles release API rate-limit failures without disrupting unrelated commands. A feature scenario verifies ChangesUpdate check resilience
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.2.5)Invalid configuration: Comment |
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>
There was a problem hiding this comment.
Pull request overview
This PR prevents WP-CLI’s background auto-update check from terminating the user’s currently running command when the update check encounters HTTP/network errors (e.g., GitHub 401/403/rate limiting). It does so by switching the auto-check to WP_CLI::runcommand() with options that capture errors/output instead of exiting the process.
Changes:
- Replace
ob_start() + WP_CLI::run_command()withWP_CLI::runcommand()forcli check-update --format=count. - Run the update check with
exit_error => falseandreturn => 'all'to capture failures/output without printing or exiting. - On failure, emit a
WP_CLI::debug()message (groupauto-update) and return early.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@features/cli-check-update.feature`:
- Around line 61-64: Update the scenario around the `wp cli version` commands to
exercise the auto-update code path, such as using a help command that triggers
the update check, or add an assertion confirming the mocked GitHub request was
made. Preserve the return-code assertions while ensuring the 403 stub is
consumed and the regression cannot pass without executing the auto-update
branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ad24f7dc-7b18-4417-a1fc-52de3ed7ae33
📒 Files selected for processing (2)
features/cli-check-update.featurephp/WP_CLI/Runner.php
| When I run `wp cli version` | ||
| Then the return code should be 0 | ||
| When I run `WP_CLI_AUTO_CHECK_UPDATE_DAYS=0 wp cli version` | ||
| Then the return code should be 0 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== auto_check_update call sites ==\n'
rg -n "auto_check_update\s*\(" php features -S || true
printf '\n== help/version related registrations ==\n'
rg -n "cli version|version" php/WP_CLI features/cli-check-update.feature -S || true
printf '\n== inspect Runner around call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
nl -ba "$file" | sed -n '1880,1975p'
fi
printf '\n== inspect feature scenario around lines 45-70 ==\n'
file=features/cli-check-update.feature
if [ -f "$file" ]; then
nl -ba "$file" | sed -n '40,75p'
fiRepository: wp-cli/wp-cli
Length of output: 11171
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== locate version command implementation ==\n'
rg -n "class .*Version|function .*version|subcommand.*version|cli version" php -S || true
printf '\n== map WP_CLI command classes related to cli ==\n'
fd -a "cli" php || true
fd -a "Version" php || trueRepository: wp-cli/wp-cli
Length of output: 1852
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== auto_check_update call sites ==\n'
rg -n "auto_check_update\s*\(" php features -S || true
printf '\n== help/version related registrations ==\n'
rg -n "cli version|version" php/WP_CLI features/cli-check-update.feature -S || true
printf '\n== inspect Runner around call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
nl -ba "$file" | sed -n '1880,1975p'
fi
printf '\n== inspect feature scenario around lines 40-75 ==\n'
file=features/cli-check-update.feature
if [ -f "$file" ]; then
nl -ba "$file" | sed -n '40,75p'
fiRepository: wp-cli/wp-cli
Length of output: 11171
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== CLI_Command::version ==\n'
file=php/commands/src/CLI_Command.php
if [ -f "$file" ]; then
awk 'NR>=1 && NR<=140 { printf "%5d %s\n", NR, $0 }' "$file"
fi
printf '\n== Runner around auto_check_update call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
awk 'NR>=1888 && NR<=1960 { printf "%5d %s\n", NR, $0 }' "$file"
fi
printf '\n== Runner around parse / dispatch to see where help branch is selected ==\n'
if [ -f "$file" ]; then
awk 'NR>=1400 && NR<=1460 { printf "%5d %s\n", NR, $0 }' "$file"
fiRepository: wp-cli/wp-cli
Length of output: 10648
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== outline CLI_Command ==\n'
ast-grep outline php/commands/src/CLI_Command.php --view expanded || trueRepository: wp-cli/wp-cli
Length of output: 1154
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file=features/cli-check-update.feature
printf '\n== relevant feature window ==\n'
awk 'NR>=45 && NR<=70 { printf "%5d %s\n", NR, $0 }' "$file"
printf '\n== request-consumption assertions in this feature ==\n'
rg -n "request|consum|HTTP 403|latest version|auto_check_update|check-update" "$file" -n -S || trueRepository: wp-cli/wp-cli
Length of output: 2241
Use a command that hits the auto-update branch wp cli version only prints the version string, so this scenario can pass without consuming the 403 stub and still miss the regression. Switch to a help path or assert that the mocked GitHub request was made.
🤖 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 `@features/cli-check-update.feature` around lines 61 - 64, Update the scenario
around the `wp cli version` commands to exercise the auto-update code path, such
as using a help command that triggers the update check, or add an assertion
confirming the mocked GitHub request was made. Preserve the return-code
assertions while ensuring the 403 stub is consumed and the regression cannot
pass without executing the auto-update branch.
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
wp cli versionto complete successfully.