Skip to content

Validate SSH alias configuration and provide clear error messages#6204

Open
Copilot wants to merge 6 commits intomainfrom
copilot/fix-ssh-alias-error-handling
Open

Validate SSH alias configuration and provide clear error messages#6204
Copilot wants to merge 6 commits intomainfrom
copilot/fix-ssh-alias-error-handling

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

When SSH aliases are misconfigured with ssh and path as separate keys (instead of embedding path in the SSH connection string), users receive cryptic foreach warnings and "Alias not found" errors.

# Misconfigured - triggers confusing errors
@staging:
  ssh: user@host
  path: /var/www/html

# Correct format
@staging:
  ssh: user@host:/var/www/html

Changes

  • Validation in Runner::set_alias(): Detect ssh + path combination and emit actionable error message
  • Defensive checks: Guard foreach loops in Runner::run_ssh_command(), Runner::set_alias(), and Configurator::get_aliases() to prevent warnings on malformed alias data
  • Test coverage: Added scenarios for common SSH alias misconfigurations

Error Message Improvement

Before:

PHP Warning: Invalid argument supplied for foreach() in phar://php/WP_CLI/Configurator.php on line 98
Error: Alias '@staging' not found.

After:

Error: Alias '@staging' is misconfigured. When 'ssh' is specified, 'path' should be included in the SSH connection string (e.g., 'user@host:/path/to/wordpress'), not as a separate key.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 366891.example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/wp-cli/wp-cli/bin/../php/boot-fs.php core install-network --title=WP CLI Network --subdomains=1 is-installed bin/wp -v origin /home/REDACTED/wor@foo sh k/wp�� 29662' var_export( defiREDACTED bin/ssh li-test-core-dowcp /wp-content /usr/local/bin/m/tmp/wp-cli-test-core-install-cache-6.9/install_c4775ff9eceb34ebd92a3deef4bd8d0b--title=WP CLI Site bash (dns block)
  • c0ff8e.example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/wp-cli/wp-cli/bin/../php/boot-fs.php core install-network --title=WP CLI Network --subdomains=1 ss-than-php-8&&~REDACTED vendor/bin/sh -ssh-alias-errorsh features/class-w/home/REDACTED/work/wp-cli/wp-cli/bin/wp (dns block)
  • example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email (dns block)
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email eature er.feature rk.f�� ature 2>/dev/null bin/wp --local user.email vendor/bin/which uniq (dns block)
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email rgo/bin/bash sh /hom�� -sqlite-integration-cache/sqlite-database-integration ssspidy <841956+swissspidy@users.noreply.github.com> (dns block)
  • host
    • Triggering command: /usr/bin/ssh ssh -i identityfile.key -T -vvv user@host cd '/path/to/wordpress'; WP_CLI_RUNTIME_ALIAS='{"@foo":{"key":"identityfile.key"}}' wp @foo '--debug' '--version' ndor/bin/bash -v (dns block)
    • Triggering command: /usr/bin/ssh ssh -i identityfile.key -T -vvv user@host cd '/path/to/wordpress'; WP_CLI_RUNTIME_ALIAS='{"@foo":{"key":"identityfile.key"}}' wp @foo '--debug' '--version' tnet/tools/mysql p mysql /home/REDACTED/.ca@foo sh bin/�� user create /home/REDACTED/.local/bin/sh submodules | heawp ABLE_WP_CRON', tcli ndor/bin/sh sh (dns block)
  • proxyhost
    • Triggering command: /usr/bin/ssh ssh -vvv -W [host]:22 proxyhost behat -- cal/bin/php (dns block)
    • Triggering command: /usr/bin/ssh ssh -vvv -W [host]:22 proxyhost core basename tnet/tools/which/tmp/wp-cli-test-core-download-cache-6.9/wp-login.php 00ee2423.4889147sh which /usr/local/bin/g@foo sh /hom�� -handling ) { define( 'DISABLE_WP_CRON', true ); } rgo/bin/sh ain..copilot/fixsh sh sh /usr/bin/php (dns block)
  • staging.example.com
    • Triggering command: /usr/bin/ssh ssh -T -vvv deploy@staging.example.com cd '/var/www/staging'; wp '--debug' 'core' 'version' cli alias rgo/bin/sh /tmp/wp-cli-testrun-phpstan-tests /tmp/wp-cli-test-core-install-ca-c sh wp bin/�� --debug --version /bin/sh ation ost (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Error message when misconfiguring SSH setting in alias is misleading</issue_title>
<issue_description>When you misconfigure the SSH setting in an alias, like omitting the path and adding a separate path: key instead, then the error message that WP-CLI provides is very misleading:

PHP Warning:  Invalid argument supplied for foreach() in phar://php/WP_CLI/Configurator.php on line 98
Error: Alias '@myalias' not found.

We should validate the settings and produce meaningful error messages that point to the actual issue instead.

Related: #5257</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 22, 2026 18:17
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…ray values

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix misleading error message for misconfigured SSH alias settings Validate SSH alias configuration and provide clear error messages Jan 22, 2026
Copilot AI requested a review from swissspidy January 22, 2026 18:22
@github-actions github-actions bot added bug command:cli Related to 'cli' command command:cli-utils labels Jan 22, 2026
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review January 22, 2026 23:02
@swissspidy swissspidy requested a review from a team as a code owner January 22, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message when misconfiguring SSH setting in alias is misleading

2 participants