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

[Form] DependencyInjectionExtension Type extension exception #36610

Closed
7ochem opened this issue Apr 28, 2020 · 1 comment
Closed

[Form] DependencyInjectionExtension Type extension exception #36610

7ochem opened this issue Apr 28, 2020 · 1 comment

Comments

@7ochem
Copy link

7ochem commented Apr 28, 2020

Symfony version(s) affected: 4.2.0 and above (currently up until 5.1)

Description
The getTypeExtensions($name) method of \Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension throws a strange exception message:

The extended type specified for the service "0" does not match the actual extended type. Expected "Vendor\Bundle\AcmeBundle\Form\FooType", given "Vendor\Bundle\AcmeBundle\Form\BarType".

See the hightlighted code lines of the getTypeExtensions() method in the additional context below, the $serviceId variable contains the integer key of the items of the $this->typeExtensionServices[$name] iterable. Apparently, this has been set to an actual service ID by a service ID guesser before Symfony went full FQCN and now it just remains a numeric key. But the thrown exception message has not been adjusted to the new situation. This results is a very unclear error.

How to reproduce
Have a Type extension's getExtendedType(s) return invalid type(s)

Possible Solution
Clarify the exception message with useful data. Also the key in the loop is therefore probably no longer needed.

Additional context

if (isset($this->typeExtensionServices[$name])) {
foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) {
$extensions[] = $extension;
$extendedTypes = [];
foreach ($extension::getExtendedTypes() as $extendedType) {
$extendedTypes[] = $extendedType;
}
// validate the result of getExtendedTypes() to ensure it is consistent with the service definition
if (!\in_array($name, $extendedTypes, true)) {
throw new InvalidArgumentException(sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".', $serviceId, $name, implode(', ', $extendedTypes)));
}
}
}

@xabbuh
Copy link
Member

xabbuh commented Apr 28, 2020

I think #36613 will provide a more helpful message.

xabbuh added a commit that referenced this issue May 2, 2020
…'t match (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] provide a useful message when extension types don't match

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36610
| License       | MIT
| Doc PR        |

Commits
-------

88d8366 provide a useful message when extension types don't match
@xabbuh xabbuh closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants