Skip to content

Improved the error message when using "@" in a decorated service #17687

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

Closed
wants to merge 4 commits into from

Conversation

javiereguiluz
Copy link
Member

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17666
License MIT
Doc PR -

@stloyd
Copy link
Contributor

stloyd commented Feb 4, 2016

👍

@dunglas
Copy link
Member

dunglas commented Feb 4, 2016

👍 (I made this mistake recently).

@@ -288,6 +288,10 @@ private function parseDefinition($id, $service, $file)
}

if (isset($service['decorates'])) {
if ('@' === $service['decorates']{0}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could $service['decorates'] be empty here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and by the way, I don't think we use braces anywhere else to access chars in string (everywhere else we use square brackets instead IIRC)

@javiereguiluz
Copy link
Member Author

I've implemented the changes asked by reviewers. This is now ready for the final review. Thanks!

@@ -288,6 +288,10 @@ private function parseDefinition($id, $service, $file)
}

if (isset($service['decorates'])) {
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" by "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] replace with [...]

@xabbuh
Copy link
Member

xabbuh commented Feb 9, 2016

I left a minor comment, but beside that 👍

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2016

AFAIK you can technically have a service id like @foo. The limitation is only in the PhpDumper (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L1342) (which is arbitrary and could be fixed in the future).
So this change is not consistent with the rest and could break code that actually references a service beginning with an @.
Dumping with the YamlDumper would work and then loading it with the YamlLoader would fail which is really strange.

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2016

If I'm right, we need a different solution.

@stof
Copy link
Member

stof commented Feb 10, 2016

@Tobion IMO, the right solution is to restrict the list of allowed chars in service ids to chars working everywhere (anything not working for the PhpDumper means it cannot work in a project wanting performance, as it would prevent dumping the container in the cache). This could start as a deprecation for now though

@Tobion
Copy link
Contributor

Tobion commented Feb 10, 2016

Yes that is probably the easiest solution. Another one would be the remove this restriction in the PhpDumper by encoding special chars (hex for example).

And IMO the better solution to this is issue here is to improve the real exception message in the ContainerBuilder: mention which service is decorating the non-existing one and maybe add suggestions for existing ones (like it is done for console commands). This would also work if we remove the restriction on service ids.

@fabpot
Copy link
Member

fabpot commented Feb 15, 2016

I'm 👍 to merge this one as is (even if technically, a service name can start with @, nobody will ever do that anyway). @javiereguiluz Can you create another PR or an issue to forbid usage of characters not supported by the dumper?

@javiereguiluz
Copy link
Member Author

Yes, I'll take care of that in the new issue #17801.

@xabbuh
Copy link
Member

xabbuh commented Feb 15, 2016

But wouldn't it indeed be better to raise this exception only in the DecoratorServicePass if the getDecoratedService() method returns a non-existent service or alias id?

@fabpot
Copy link
Member

fabpot commented Feb 29, 2016

@xabbuh I think it's better to throw the exception as early as possible; it is a YAML issue, so it should probably be dealt with there.

@xabbuh
Copy link
Member

xabbuh commented Mar 1, 2016

@fabpot The only thing is that technically, you can have a service id starting with @.

But anyway, I think it makes sense to restrict the list of allowed characters and deprecate everything else. So 👍 for doing this check for the YAML part only.

@fabpot
Copy link
Member

fabpot commented Mar 3, 2016

Thank you @javiereguiluz.

fabpot added a commit that referenced this pull request Mar 3, 2016
…ervice (javiereguiluz)

This PR was squashed before being merged into the 2.7 branch (closes #17687).

Discussion
----------

Improved the error message when using "@" in a decorated service

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17666
| License       | MIT
| Doc PR        | -

Commits
-------

e7690ba Improved the error message when using "@" in a decorated service
@fabpot fabpot closed this Mar 3, 2016
This was referenced Mar 25, 2016
@fabpot fabpot mentioned this pull request Mar 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants