Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Improve error message for missing extensions able to load config files #54336

Closed
@javiereguiluz

Description

@javiereguiluz

Related to symfony/symfony-docs#19655


When you have some bundle configuration file in your app and the bundle is not installed/enabled, you see an error message like this:

There is no extension able to load the configuration for "security"
(in (...)/config/packages/security.yaml). Looked for namespace "security",
found "framework", "web_server", "maker", "doctrine_cache", "doctrine",
"doctrine_migrations", "twig", "...", "knp_paginator" in
(...)/config/packages/security.yaml (which is loaded in
resource "(...)/config/packages/security.yaml").

This is generated in:

throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s". Looked for namespace "%s", found "%s".', $namespace, $alias, $extensions ? implode('", "', $extensions) : 'none'));

and

throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $namespace, $this->file, $namespace, $extensions ? implode('", "', $extensions) : 'none'));


Problem: this error message is probably not perfectly clear for all developers, mostly newcomers. See e.g. https://stackoverflow.com/questions/55279011/there-is-no-extension-able-to-load-the-configuration-for-security

Possible solution: if we agree on improving this error message, we could do the same we do in other parts of Symfony, such as:

if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
}

and:

// If the slugger is used but the String component is not available, we should throw an error
if (!ContainerBuilder::willBeAvailable('symfony/string', SluggerInterface::class, ['symfony/framework-bundle'])) {
$container->register('slugger', SluggerInterface::class)
->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
} else {

We could remind developers to install the related bundle of a missing extension. Just hardcoding a few of the popular first-party/second-party bundles (security, twig, doctrine, etc.) would be enough.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)DependencyInjection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions