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

Bug: 'Command "cli" is not defined' in Tinkerwell #283

Open
5 tasks done
montchr opened this issue Apr 12, 2023 · 1 comment
Open
5 tasks done

Bug: 'Command "cli" is not defined' in Tinkerwell #283

montchr opened this issue Apr 12, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@montchr
Copy link

montchr commented Apr 12, 2023

Terms

Description

What's wrong?

Tinkerwell fails to run with the following error:

[2023-04-12 18:24:19] development.ERROR: Command "cli" is not defined. {"exception":"[object](Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"cli\" is not defined. at /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php:694)
[stacktrace]
#0 /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php(259): Symfony\\Component\\Console\\Application->find('cli')
#1 /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#2 /var/www/html/vendor/illuminate/console/Application.php(102): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#3 /var/www/html/vendor/roots/acorn/src/Illuminate/Foundation/Console/Kernel.php(155): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /var/www/html/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(150): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 /var/www/html/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(110): Roots\\Acorn\\Bootloader->bootConsole(Object(Roots\\Acorn\\Application))
#6 /var/www/html/web/app/themes/logan-center/functions.php(43): Roots\\Acorn\\Bootloader->boot()
#7 /var/www/html/web/wp/wp-settings.php(591): include('/var/www/html/w...')
#8 /var/www/html/.tinkerwell/BedrockTinkerwellDriver.php(19): require_once('/var/www/html/w...')
#9 phar:///tmp/tinker.phar/src/Concerns/DriverAware.php(11): BedrockTinkerwellDriver->bootstrap('/var/www/html')
#10 phar:///tmp/tinker.phar/src/Actions/CliAction.php(29): _HumbugBox0bc95c13c4b6\\Tinkerwell\\Actions\\CliAction->detectDriver('/var/www/html')
#11 phar:///tmp/tinker.phar/src/ActionInvoker.php(37): _HumbugBox0bc95c13c4b6\\Tinkerwell\\Actions\\CliAction->__construct(Object(stdClass))
#12 phar:///tmp/tinker.phar/src/ActionInvoker.php(18): _HumbugBox0bc95c13c4b6\\Tinkerwell\\ActionInvoker->setUpAction(Object(stdClass))
#13 phar:///tmp/tinker.phar/index.php(25): _HumbugBox0bc95c13c4b6\\Tinkerwell\\ActionInvoker->execute()
#14 /tmp/tinker.phar(12): require('phar:///tmp/tin...')
#15 {main}
"}

It looks like the cli service provider expected by Symfony\\Component\\Console\\Application is unavailable.

Related to #49, but not the same issue.

What have you tried?

I've tried not using Tinkerwell, which works.

Not sure how to proceed.

What insights have you gained?

See the Discourse thread for more context.

Possible solutions

???

See https://github.com/tinkerwellapp/drivers/blob/master/src/Drivers/LaravelTinkerwellDriver.php for an example of how Tinkerwell would load a Laravel application.

Also see https://github.com/tinkerwellapp/drivers/blob/master/src/Drivers/SymfonyTinkerwellDriver.php, though it doesn't provide much more insight.

Temporary workarounds

Others in the Discourse thread have reported that commenting out the \Roots\Acorn\Bootloader::bootConsole method resolves the issue. I haven't tried this, because I would prefer a permanent fix instead of maintaining commenting out code in Acorn. So I just can't use Tinkerwell for the time being because of the conflict.

Steps To Reproduce

  1. Install Tinkerwell
  2. In a Bedrock-powered environment using Acorn: configure a custom driver following the prior art available in https://github.com/pixelcollective/dreamdefenders.org/blob/cae3fbc7c3408edea112ea98cd91651be0e80b4b/.tinkerwell/BedrockTinkerwellDriver.php or in my gist (only difference is replacing a deprecated call to \Roots\app)
  3. In Tinkerwell, execute something like home_url()

Expected Behavior

Tinkerwell should work. The console kernel should have all the necessary dependencies.

Actual Behavior

Tinkerwell fails due to missing app services.

Relevant Log Output

[2023-04-12 18:24:19] development.ERROR: Command "cli" is not defined. {"exception":"[object](Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"cli\" is not defined. at /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php:694)
[stacktrace]
#0 /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php(259): Symfony\\Component\\Console\\Application->find('cli')
#1 /var/www/html/web/app/themes/logan-center/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#2 /var/www/html/vendor/illuminate/console/Application.php(102): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#3 /var/www/html/vendor/roots/acorn/src/Illuminate/Foundation/Console/Kernel.php(155): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /var/www/html/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(150): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 /var/www/html/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(110): Roots\\Acorn\\Bootloader->bootConsole(Object(Roots\\Acorn\\Application))
#6 /var/www/html/web/app/themes/logan-center/functions.php(43): Roots\\Acorn\\Bootloader->boot()
#7 /var/www/html/web/wp/wp-settings.php(591): include('/var/www/html/w...')
#8 /var/www/html/.tinkerwell/BedrockTinkerwellDriver.php(19): require_once('/var/www/html/w...')
#9 phar:///tmp/tinker.phar/src/Concerns/DriverAware.php(11): BedrockTinkerwellDriver->bootstrap('/var/www/html')
#10 phar:///tmp/tinker.phar/src/Actions/CliAction.php(29): _HumbugBox0bc95c13c4b6\\Tinkerwell\\Actions\\CliAction->detectDriver('/var/www/html')
#11 phar:///tmp/tinker.phar/src/ActionInvoker.php(37): _HumbugBox0bc95c13c4b6\\Tinkerwell\\Actions\\CliAction->__construct(Object(stdClass))
#12 phar:///tmp/tinker.phar/src/ActionInvoker.php(18): _HumbugBox0bc95c13c4b6\\Tinkerwell\\ActionInvoker->setUpAction(Object(stdClass))
#13 phar:///tmp/tinker.phar/index.php(25): _HumbugBox0bc95c13c4b6\\Tinkerwell\\ActionInvoker->execute()
#14 /tmp/tinker.phar(12): require('phar:///tmp/tin...')
#15 {main}
"}

Versions

v3.1.0

@montchr montchr added the bug Something isn't working label Apr 12, 2023
@galatanovidiu
Copy link

I will also add my comment from https://discourse.roots.io/t/tinkerwell-with-sage-10-bedrock/24821/6 here for anyone with the same problem.

For me, this was a problem with Tinkerwell and when running PHP unit tests using Pest.
When running pest tests, instead of running the tests, acorn is taking over, and it will show the available commands.
A temporary, simple solution in my case was:

if( isset( $_SERVER['argv'] ) && ! in_array( 'acorn', $_SERVER['argv'] ) ){
	putenv( 'APP_RUNNING_IN_CONSOLE=false' );
}

I do not use bedrock, and Acorn is loaded through a mu-plugin.
I’ve added the snippet above just before loading vendor/autoload.php

Since I posted this on discourse.roots.io, I have had no problems with this approach, even if this looks a bit hacky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants