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 5 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>
| Try using a GITHUB_TOKEN | ||
| """ | ||
|
|
||
| Scenario: Does not fail unrelated command when background update check is rate limited |
There was a problem hiding this comment.
At first glance, wp help in an empty dir makes sense, that path does call auto_check_update(). But I don't think this scenario actually exercises the fix: auto_check_update() bails out well before the check-update call, first on ! inside_phar() (Behat runs from source, not a Phar) and then on ! posix_isatty( STDOUT ) (Behat pipes STDOUT, so it's never a TTY). So the runcommand is never reached, and the 403 mock is never hit by the auto path. Quickest way to confirm: revert the Runner.php hunk and this scenario still passes. That's also why codecov/patch is red, the new branch gets no coverage.
I'd rather we either drop this scenario (the manual repro in the PR description is the real evidence, and a green check that guards nothing is worse than no check), or, if we want genuine coverage, pull the 'run check-update and interpret the result' core out into a testable seam and unit-test it with a mocked runcommand. A full feature test would need a test-only bypass of the Phar/TTY guards, which I don't think is worth it here.
| ] | ||
| ); | ||
| $count = ob_get_clean(); | ||
| if ( ! is_object( $result ) || $result->return_code ) { |
There was a problem hiding this comment.
Minor: with return => 'all', runcommand always hands back the object, so ! is_object( $result ) can't actually be true here. Harmless as defensive code, so feel free to leave it.
| ); | ||
| $count = ob_get_clean(); | ||
| if ( ! is_object( $result ) || $result->return_code ) { | ||
| WP_CLI::debug( 'Background update check failed: ' . ( is_object( $result ) ? trim( $result->stderr ) : '' ), 'auto-update' ); |
There was a problem hiding this comment.
Tiny thing: runcommand already trims stderr on the way out (it builds the all object with trim( $stderr )), so the trim() here is redundant.
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 help, including when auto-check timing is disabled.