getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.59k stars 1.41k forks source link

Unhelpful error when plugins (or pages) directory is not found #3495

Open drzraf opened 2 years ago

drzraf commented 2 years ago

When user:// points to a directory missing a plugins/ directory (for whatever reason, from permission to setup.php, streams.yaml, to debugging config order/override), this strange error is thrown (Failed to open dir: plugins:// does not exist.) with this stack:

Xdebug: user triggered in /grav/vendor/rockettheme/toolbox/ResourceLocator/src/UniformResourceIterator.php on line 102
Call Stack
#   Time    Memory  Function    Location
1   0.0002  428664  {main}( )   .../index.php:0
2   0.0053  486448  Grav\Common\Grav->process( )    .../index.php:58
3   0.0086  661160  Grav\Framework\RequestHandler\RequestHandler->handle( ) .../Grav.php:304
4   0.0103  665816  Grav\Framework\RequestHandler\RequestHandler->handle( ) .../RequestHandlerTrait.php:62
5   0.0103  665912  Grav\Common\Processors\InitializeProcessor->process( )  .../RequestHandlerTrait.php:50
6   0.0103  666664  Grav\Common\Processors\InitializeProcessor->initializeConfig( ) .../InitializeProcessor.php:73
7   0.0104  667040  Grav\Common\Grav->offsetGet( )  .../InitializeProcessor.php:181
8   0.0104  667040  Grav\Common\Service\ConfigServiceProvider->Grav\Common\Service\{closure:/grav/system/src/Grav/Common/Service/ConfigServiceProvider.php:49-58}( )    .../Container.php:118
9   0.0104  667040  Grav\Common\Service\ConfigServiceProvider::load( )  .../ConfigServiceProvider.php:50
10  0.0111  676672  Grav\Common\Config\CompiledConfig->load( )  .../ConfigServiceProvider.php:135
11  0.0111  676672  Grav\Common\Config\CompiledConfig->load( )  .../CompiledConfig.php:61
12  0.0150  676928  Grav\Common\Config\CompiledConfig->loadFiles( ) .../CompiledBase.php:112
13  0.0157  683032  Grav\Common\Config\CompiledConfig->loadFile( )  .../CompiledBase.php:180
14  0.0157  683032  Grav\Common\Config\Config->join( )  .../CompiledConfig.php:111
15  0.0157  683032  Grav\Common\Config\Config->blueprints( )    .../Data.php:120
16  0.0157  683032  Grav\Common\Service\ConfigServiceProvider::Grav\Common\Service\{closure:/grav/system/src/Grav/Common/Service/ConfigServiceProvider.php:131-133}( )  .../Data.php:272
17  0.0157  683032  Grav\Common\Grav->offsetGet( )  .../ConfigServiceProvider.php:132
18  0.0157  683032  Grav\Common\Service\ConfigServiceProvider->Grav\Common\Service\{closure:/grav/system/src/Grav/Common/Service/ConfigServiceProvider.php:45-47}( )    .../Container.php:118
19  0.0157  683032  Grav\Common\Service\ConfigServiceProvider::blueprints( )    .../ConfigServiceProvider.php:46
20  0.0161  755376  Grav\Common\Config\CompiledBlueprints->load( )  .../ConfigServiceProvider.php:105
21  0.0161  755472  Grav\Common\Config\CompiledBlueprints->loadCompiledFile( )  .../CompiledBase.php:112
22  0.0230  755568  Grav\Common\Config\CompiledBlueprints->checksum( )  .../CompiledBase.php:211
23  0.0231  759664  Grav\Common\Config\CompiledBlueprints->getTypes( )  .../CompiledBlueprints.php:45
24  0.0231  759664  Grav\Common\Grav->offsetGet( )  .../CompiledBlueprints.php:68
25  0.0231  759664  Grav\Common\Grav->Grav\Common\{closure:/grav/system/src/Grav/Common/Grav.php:708-710}( )    .../Container.php:118
26  0.0234  766264  Grav\Common\Plugins->__construct( ) .../Grav.php:709
27  0.0234  766264  RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator->getIterator( )  .../Plugins.php:47
28  0.0234  783728  RocketTheme\Toolbox\ResourceLocator\UniformResourceIterator->__construct( ) .../UniformResourceLocator.php:45
29  0.0234  783728  RocketTheme\Toolbox\ResourceLocator\UniformResourceIterator->rewind( )  .../UniformResourceIterator.php:47
30  0.0234  783816  xdebug_print_function_stack ( ) .../UniformResourceIterator.php:102

A more explicit error about uninitialized or badly initialized streams would really help (in particular, printing the actual path(s) looked for)

drzraf commented 2 years ago

More generally, it's really hard to debug streams when something goes wrong. problems does not help (it may even keeps correctly configured website from running https://github.com/getgrav/grav-plugin-problems/issues/28) but probably should. WIth Grav 1.7, I could set GRAV_ENVIRONMENT in httpd configuration, or a setup.php file, or a user/config/streams.yaml file overriden by localhost/config/* files. When these are needed, it's not rare to struggle with the above errors or page not found but it's almost impossible to figure out what's wrong with Grav configuration, because Grav won't says which files it considered, which it ignored, and what are the paths that it's actually considering when looking for pages/config/plugins/...

It'd would be a lifesaver to obtain a dump of the actual paths in such a case.

drzraf commented 2 years ago

Another thing that may need to be fixed in https://learn.getgrav.org/17/advanced/multisite-setup :

Screenshot from 2021-12-15 16-09-52

This environment setup key does not seem to be used.

return [
    'environment' => $name,
    ...
];
drzraf commented 2 years ago

I'd add that Clockwork (when debugging is actually taken into account) does help! It shows actual configuration, streams, ... but if you get a 404 even though streams are corrects, then it's very hard to figure out what's happening.