Skip to content

Literal "%s" in warning when default branch JSON response cannot be decoded #265

Done

Description

@manishsongirkar

Description

When wp package install cannot decode the GitHub API response for a package's default branch, the warning prints a literal %s instead of the package name.

Where

src/Package_Command.php, in get_github_default_branch():

$package_data = json_decode( $response->body );

if ( JSON_ERROR_NONE !== json_last_error() ) {
	WP_CLI::warning( "Couldn't fetch default branch for package '%s' (failed to decode JSON response). Presuming default branch is 'master'." );
	return 'master';
}

The string has no sprintf() call and no argument. WP_CLI::warning() does not format the message, so the %s is printed as is.

The two sibling warnings in the same method both use sprintf( ..., $package_name ). One is the non-2xx status case above this code. The other is the invalid default_branch case below it. $package_name is in scope here.

Steps to reproduce

  1. Make the GitHub API request for the repository return HTTP 200 with a body that is not JSON. A proxy or captive portal page can do this.
  2. Run wp package install https://github.com/<owner>/<repo>.git.

Expected

Warning: Couldn't fetch default branch for package '<owner>/<repo>' (failed to decode JSON response). Presuming default branch is 'master'.

Actual

Warning: Couldn't fetch default branch for package '%s' (failed to decode JSON response). Presuming default branch is 'master'.

Suggested fix

Wrap the message in sprintf(), the same way as the sibling warnings:

WP_CLI::warning(
	sprintf(
		"Couldn't fetch default branch for package '%s' (failed to decode JSON response). Presuming default branch is 'master'.",
		$package_name
	)
);

Environment

  • WP-CLI 3.0.1. The bundled code has the same line as main at 6487f3a.
  • PHP 8.6.0

Notes

  • I reproduced this with the real wp binary against a local mock of api.github.com that returned HTTP 200 with the body not json. With the suggested fix applied, the same run prints 'example/some-pkg' in place of '%s'.
  • There is no existing test for the "Presuming default branch is 'master'" warnings. The method is private and calls Utils\http_request against a hard-coded api.github.com URL, so a test needs an HTTP mock or proxy. I plan no new test for this one-string fix, unless you want one.
  • I searched open and closed issues and PRs for "%s", "sprintf" and "default branch". I found no existing report.

Request

Could you please assign this issue to me? I would like to raise the PR for the fix.

Activity

  1. added
    command:package-install
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommand:package-install

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions