getgrav / grav-plugin-admin

Grav Admin Plugin
http://getgrav.org
MIT License
355 stars 227 forks source link

Calling Grav::instance()['plugins']->all() throws RuntimeException #1986

Closed Flamenco closed 3 years ago

Flamenco commented 3 years ago

version Grav v1.7.0-rc.17 - Admin v1.10.0-rc.17

Here is the error

RuntimeException (500)
Cannot load blueprint blueprints://flex-objects/pages.yaml: Invalid resource theme://

This should not bring down the whole stack.

Here is the code throwing the exception

/Users/steven/Sites/grav-1.7.0-rc.17/vendor/rockettheme/toolbox/Blueprints/src/BlueprintForm.php
                    // Load and extend blueprints.
                    $data = $this->doLoad($files, $extends);

                    $this->items = (array)array_shift($data);

                    foreach ($data as $content) {
                        $this->extend($content, true);
                    }
                }
            }

            // Import blueprints.
            $this->deepInit($this->items);
        } catch (\Exception $e) {
            $filename = $this->filename;
            if (is_array($filename)) {
                $filename = implode(' | ', $filename);
            }

            throw new RuntimeException(sprintf('Cannot load blueprint %s: %s', $filename, $e->getMessage()), 500, $e);
        }

        return $this;
    }

    /**
     * Initialize blueprints with its dynamic fields.
     *
     * @return $this
     */
    public function init()
    {

Here is my client code. (called from plugins:initialized hook)

    public static function checkAllPluginDependencies()
    {
        foreach (Grav::instance()['plugins']->all() as $plugin) {
            if (!self::checkDependencies(($plugin))) {
                Grav::instance()['log']->warn("Plugin $plugin->name has dependency issues.");
            }
        }
    }
rhukster commented 3 years ago

Please test with latest rc.19 that was just released

mahagr commented 3 years ago

@Flamenco Make sure you're calling this only after onThemeInitialized() event; it will fix the issue.

That said, I kind of agree that looping through plugins should not cause this. Do you know which plugin has this issue?

mahagr commented 3 years ago

I just checked your loop and it works in my sandbox test environment. It must be some plugin doing bad things too early.