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

Gracefully handle and report ContainerNotInitializedException #67

Closed
mglaman opened this issue May 3, 2019 · 1 comment

Comments

1 participant
@mglaman
Copy link
Owner

commented May 3, 2019

Reference: mglaman/drupal-check#42

Currently, we skip known Drupal core modules which call \Drupal:: outside of the scope of any function in their .install file.

                $ignored_install_files = ['entity_test', 'entity_test_update', 'update_test_schema'];
                if (!in_array($module_name, $ignored_install_files, true)) {
                    require $module_dir . '/' . $module_name . '.install';
                }

Turns out that the Examples module does this, too, in tabledrag_example.

module_load_include('inc', 'tabledrag_example', 'tabledrag_example.data');

The loading of modules should be wrapped in a try/catch for this exception and throw a custom scoped exception. This can help the end user understand why this happened and how to fix it.

@mglaman

This comment has been minimized.

Copy link
Owner Author

commented May 7, 2019

We have it for .module, .theme, and .profile through

    protected function loadExtension(Extension $extension): void
    {
        try {
            $extension->load();
        } catch (\Throwable $e) {
            // Something prevented the extension file from loading.
            // This can happen when drupal_get_path or drupal_get_filename are used outside of the scope of a function.
        }
    }

@mglaman mglaman closed this in #68 May 7, 2019

PHPStan + Drupal automation moved this from To do to Done May 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.