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

Incorrect message when plugins directory not exists using bake #909

Closed
kicaj opened this issue Feb 20, 2023 · 13 comments · Fixed by #911
Closed

Incorrect message when plugins directory not exists using bake #909

kicaj opened this issue Feb 20, 2023 · 13 comments · Fixed by #911

Comments

@kicaj
Copy link

kicaj commented Feb 20, 2023

Description

During creating new plugin using command bin/cake bake plugin PluginName with not existed plugins directory.

Bake:

  • no returns information for required plugins directory;
  • returns strange information:
[Cake\Core\Exception\MissingPluginException] Plugin  could not be found. in /var/www/html/vendor/cakephp/cakephp/src/Core/PluginCollection.php on line 143
Exception Attributes: array (
  'plugin' => '',
)
Stack Trace:
- /var/www/html/vendor/cakephp/cakephp/src/Core/PluginCollection.php:257
...

Bake Version

2.8.2

CakePHP Version

4.4.11

@kicaj kicaj added the defect label Feb 20, 2023
@dereuromark dereuromark added this to the 2.x (CakePHP 4) milestone Feb 20, 2023
@dereuromark
Copy link
Member

dereuromark commented Feb 20, 2023

I can reproduce this, for some reason the PluginCollection is throwing the exception a bit too eagerly.

@dereuromark
Copy link
Member

dereuromark commented Feb 20, 2023

Looks related to cakephp/cakephp#16374
cc @ADmad

Should we try catch this?

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

The error is unrelated to that PR.

PluginCommand needs to check whether the directory for $this->path actually exists

$this->path = current(App::path('plugins'));

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

It does seem like cakephp/cakephp#16374 uncovered this issue :)

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

@kicaj Can you provide the full stack trace please.

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

Hmm.. I am unable to reproduce this with the latest core and bake releases. Bake just creates the missing plugins directory (and the plugin folder and files) without any errors.

@LordSimal
Copy link
Contributor

I can confirm the error with cakephp/cakephp 4.4.5 and cakephp/bake 2.7.1
This only happens, if the plugins directory is removed manually since the cakephp/app project template does indeed create a empty plugins directory with .gitkeep file in there.

Here is the stacktrace:

-> % bin/cake bake plugin PluginName
Plugin Name: PluginName
Plugin Directory: /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/plugins/PluginName
-------------------------------------------------------------------------------
Look okay? (y/n/q) 
[y] > 
2023-02-21 05:30:00 error: [Cake\Core\Exception\MissingPluginException] Plugin  could not be found. in /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php on line 143
Exception Attributes: array (
  'plugin' => '',
)
Stack Trace:
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php:257
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php:219
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/Plugin.php:87
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php:193
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php:115
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php:81
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/BaseCommand.php:189
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:334
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php:172
- /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/bin/cake.php:12

Stack Trace:

deprecationWarning /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/functions.php, line 321
Cake\Error\ExceptionTrap::renderer() /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Error/ExceptionTrap.php, line 123
Cake\Error\ExceptionTrap::handleException() /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Error/ExceptionTrap.php, line 239
[main] [internal], line ??
[Cake\Core\Exception\MissingPluginException] Plugin  could not be found. in /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php on line 143

Exception Attributes

array (
  'plugin' => '',
)

Stack Trace:

#0 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php(257): Cake\Core\PluginCollection->findPath('')
#1 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php(219): Cake\Core\PluginCollection->create('')
#2 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/Plugin.php(87): Cake\Core\PluginCollection->get('')
#3 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php(193): Cake\Core\Plugin::templatePath('')
#4 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php(115): Bake\Command\PluginCommand->_generateFiles('PluginName', '/Users/kevinpfe...', Object(Cake\Console\Arguments), Object(Cake\Console\ConsoleIo))
#5 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/bake/src/Command/PluginCommand.php(81): Bake\Command\PluginCommand->bake('PluginName', Object(Cake\Console\Arguments), Object(Cake\Console\ConsoleIo))
#6 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/BaseCommand.php(189): Bake\Command\PluginCommand->execute(Object(Cake\Console\Arguments), Object(Cake\Console\ConsoleIo))
#7 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php(334): Cake\Console\BaseCommand->run(Array, Object(Cake\Console\ConsoleIo))
#8 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php(172): Cake\Console\CommandRunner->runCommand(Object(Bake\Command\PluginCommand), Array, Object(Cake\Console\ConsoleIo))
#9 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/bin/cake.php(12): Cake\Console\CommandRunner->run(Array)
#10 {main}

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

I can confirm the error with cakephp/cakephp 4.4.5 and cakephp/bake 2.7.1

Latest versions are cakephp/cakephp 4.4.11 and cakephp/bake 2.8.2

@LordSimal
Copy link
Contributor

LordSimal commented Feb 21, 2023

This issue still persists for me when using cakephp/cakephp 4.4.11 and cakephp/bake 2.8.2

kevinpfeifer@Kevins-MBP [05:41:18] [~/Documents/CakePHP-Videos/02_requirements_and_installation/cms] [master *]
-> % composer show cakephp/cakephp | grep versions
versions : * 4.4.11
kevinpfeifer@Kevins-MBP [05:41:28] [~/Documents/CakePHP-Videos/02_requirements_and_installation/cms] [master *]
-> % composer show cakephp/bake | grep versions
versions : * 2.8.2
kevinpfeifer@Kevins-MBP [05:41:32] [~/Documents/CakePHP-Videos/02_requirements_and_installation/cms] [master *]
-> % bin/cake bake plugin PluginName              
[Cake\Core\Exception\MissingPluginException] Plugin PluginName could not be found. in /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php on line 143

Exception Attributes

array (
  'plugin' => 'PluginName',
)

Stack Trace:

#0 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Core/PluginCollection.php(257): Cake\Core\PluginCollection->findPath('PluginName')
#1 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Http/BaseApplication.php(129): Cake\Core\PluginCollection->create('PluginName', Array)
#2 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/src/Application.php(67): Cake\Http\BaseApplication->addPlugin('PluginName')
#3 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php(195): App\Application->bootstrap()
#4 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/vendor/cakephp/cakephp/src/Console/CommandRunner.php(133): Cake\Console\CommandRunner->bootstrap()
#5 /Users/kevinpfeifer/Documents/CakePHP-Videos/02_requirements_and_installation/cms/bin/cake.php(12): Cake\Console\CommandRunner->run(Array)
#6 {main}

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

There problem is here. The default value for theme is set to empty string and has() does a isset() check. So templatePath() gets called with an empty string. (I have a default theme set hence I couldn't reproduced it)

if ($args->hasOption('theme')) {
$paths[] = Plugin::templatePath($args->getOption('theme'));

@LordSimal
Copy link
Contributor

Well then it should be cakephp/bake's command responsibility to make sure the configured plugin directory is present at all, right? If it is not present, create it.

@ADmad
Copy link
Member

ADmad commented Feb 21, 2023

Bake does create the plugins directory if missing but this theme check is done before the file generation starts.

Plugin::templatePath() shouldn't be called with an empty string, so the if check should be updated accordingly or perhaps change the default value for theme option from empty string to null so that if ($args->hasOption('theme')) check suffices.

@LordSimal
Copy link
Contributor

LordSimal commented Feb 21, 2023

Then go ahead and fix it yourself. I am unable to fix it with your approach because setting

'default' => Configure::read('Bake.theme') ?? ''

to

'default' => Configure::read('Bake.theme'),

doesn't fix it and I don't understand the difference between making sure the directory is present beforehand and your weird theme approach which should automatically create the directory (which it doesn't for me as well).

Why should the theme flag/option be responsible for creating the plugins directory?

ADmad added a commit that referenced this issue Feb 21, 2023
This was caused due to `Bake.theme` option defaulting to empty string
instead of null and hence a plugin with empty name was being searched
causing an exception.

Closes #909
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants