Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal Error on listing packages #59

Closed
playmono opened this issue Dec 19, 2017 · 14 comments
Closed

PHP Fatal Error on listing packages #59

playmono opened this issue Dec 19, 2017 · 14 comments

Comments

@playmono
Copy link
Contributor

playmono commented Dec 19, 2017

Hi,

Running this command:
./wp-cli.phar package list

Im having this PHP Fatal Error:

PHP Fatal error:  Uncaught RuntimeException: Failed to execute git clone --mirror 'git@github.com:wp-cli/admin-command.git' '/home/user/.cache/composer/vcs/git-github.com-wp-cli-admin-command.git/'

 in phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Util/Git.php:310
Stack trace:
#0 phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Util/Git.php(199): Composer\Util\Git->throwException('Failed to execu...', 'git@github.com:...')
#1 phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Util/Git.php(226): Composer\Util\Git->runCommand(Object(Closure), 'git@github.com:...', NULL, true)
#2 phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Repository/Vcs/GitDriver.php(60): Composer\Util\Git->syncMirror('git@github.com:...', '/home/user...')
#3 phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Repository/Vcs/GitHubDriver.php(508): Composer\Repository\Vcs\GitDri in phar:///var/www/bin/wp-cli.phar/vendor/composer/composer/src/Composer/Util/Git.php on line 310

The thing is I dont have permission to execute this line git clone --mirror 'git@github.com:wp-cli/admin-command.git' '/home/user/.cache/composer/vcs/git-github.com-wp-cli-admin-command.git/', so despite my error I think wp-cli should control the RuntimeException to not give a PHP Fatal Error.

@playmono
Copy link
Contributor Author

If I use for example:
./bin/wp-cli.phar package install git@github.com:wp-cli/admin-command.git

things works as expected, result is:

Installing package wp-cli/admin-command (dev-master)
Updating /home/user/.wp-cli/packages/composer.json to require the package...
Registering git@github.com:wp-cli/admin-command.git as a VCS repository...
Using Composer to install the package...
---
Loading composer repositories with package information
Warning: Failed to execute git clone --mirror 'git@github.com:wp-cli/admin-command.git' '/home/user/.cache/composer/vcs/git-github.com-wp-cli-admin-command.git/'


---
Error: Package installation failed. Reverted composer.json

@gitlost
Copy link
Contributor

gitlost commented Dec 19, 2017

Could you try adding a personal access token https://github.com/settings/tokens (scope: repo: public_repo Access public repositories) and then export GITHUB_TOKEN=<token> and see if that fixes it for you? (See also #44 (comment)).

Edit: or you probably know that and just want the PHP fatal trapped?!?

@playmono
Copy link
Contributor Author

Thank you, I was trying to fix the error, I didn't know how to solve it and your solution worked for me.

Anyway, I was saying despite my error, I think wp-cli should contemplate this case for not giving PHP Fatal Error, instead a catched Warning.

My last question is: Is necessary then, have a github account + token in order to make this library work?

Thank you.

@gitlost
Copy link
Contributor

gitlost commented Dec 19, 2017

I think wp-cli should contemplate this case for not giving PHP Fatal Error, instead a catched Warning.

Agreed!

Is necessary then, have a github account + token in order to make this library work?

I think if you use the ssh git@github.com: url then yes. If you use the recommended https url https://github.com/ then no I don't think so. Could you try

unset GITHUB_TOKEN
./bin/wp-cli.phar package install https://github.com/wp-cli/admin-command.git

instead and see if that works for you?

@playmono
Copy link
Contributor Author

Library is giving me errors constantly about ssh git@github.com. But it's ok, I will try to make it work.

@gitlost
Copy link
Contributor

gitlost commented Dec 19, 2017

Okay ta, I did notice last time I looked that Composer uses git@github.com: internally anyway in some situations for some reason even if you give a https url, but the issue is complicated by what's already in your ~/.wp-cli/packages/composer.json and whether you have a ~/.composer/auth.json or not.

It would be good to come up with a definitive answer that can be used in error messages and in doc...

@playmono
Copy link
Contributor Author

Thank you for your answer, thats exactly what is happening. Even if I delete ~/.wp-cli/, ~/.composer and ~/.cache the thing dont works. I thought maybe that folders contained some cache repo related to git@github.com but didnt works.

I'm annoyed because when I started with wp-cli, everything worked perfect, and now I don't know what changed (Tried to "restore to initial mode" deleting all that folders etc but didnt works).

I will looking into this problem this days and hopefully will bring a solution.

Thanks.

@playmono
Copy link
Contributor Author

playmono commented Dec 21, 2017

In my research I discovered that command: wp package list connects with

https://api.github.com/repos/wp-cli/admin-command

and this URL is giving me:

{
  "message": "API rate limit exceeded for xx.xxx.xx.xx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
  "documentation_url": "https://developer.github.com/v3/#rate-limiting"
}

Then sometimes I can list my packages and sometimes cannot.

Is this the correct behaviour of the wp-cli?

Thank you.

Edit: More insight,

https://api.github.com/rate_limit

Is giving me:

{ "resources": { "core": { "limit": 60, "remaining": 0, "reset": 1513854670 }, "search": { "limit": 10, "remaining": 10, "reset": 1513854068 }, "graphql": { "limit": 0, "remaining": 0, "reset": 1513857608 } }, "rate": { "limit": 60, "remaining": 0, "reset": 1513854670 } }

@gitlost
Copy link
Contributor

gitlost commented Dec 21, 2017

Ah you're getting rate limiting, then this does require the GITHUB_TOKEN to be set to up your quota. If you're testing stuff then you can run into this especially.

Is this the correct behaviour of the wp-cli?

Well that particular issue is out of wp-cli's hands, and should be workaroundable using GITHUB_TOKEN, so "yes"!

It does make it awkward to test whether using the https url rather than the ssh url would allow one to not have to have a token.

Do you have particular circumstances where needing to set up a token is not practical or convenient?

@playmono
Copy link
Contributor Author

playmono commented Dec 21, 2017

Setting a token is very unpractical and inconvenient if I want to make an application using wp-cli that is replicated in a lot of servers analyzing wordpress installations. I mean, I dont want to create a github account just for this, and of course I dont want to use my personal github account for this.

In adittion, what's the point in connecting to github API when I just want to list my packages that I installed locally? I don't get it.

I think this approach is more interesting:
#60 (Just an example, you can control this as you want)

Result is:

+---------------------------+-------------+------------+---------------------------+---------------------------+
| name | authors | version | update | update_version |
+---------------------------+-------------+------------+---------------------------+---------------------------+
| wp-cli/admin-command | | dev-master | Error whith Github Driver | Error whith Github Driver |
| wp-cli/wp-super-cache-cli | WP-CLI Team | dev-master | none | |
+---------------------------+-------------+------------+---------------------------+---------------------------+

@gitlost
Copy link
Contributor

gitlost commented Dec 21, 2017

what's the point in connecting to github API when I just want to list my packages that I installed locally?

The reason it's doing it is to check for updates. It's also why it's so slow. Maybe a package list option to suppress this would be worth having?

@playmono
Copy link
Contributor Author

playmono commented Dec 21, 2017

Well, that will be the perfect solution I think. Anyway I see that more as a feature than a bug fixed.

I mean, if you want to check for updates (and this will be the default option I think) but API calls limit is reached you should control it.

@gitlost
Copy link
Contributor

gitlost commented Dec 21, 2017

Yes, it would be a new feature, with a separate new issue.

@gitlost
Copy link
Contributor

gitlost commented Jan 3, 2018

Going to close this via PR #60 and the new issues #61 and #62. Thanks for all your help @playmono !

@gitlost gitlost closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants