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

Skip to content

[DependencyInjection] Improve an exception message #33092

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

Merged
merged 1 commit into from
Aug 9, 2019

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Aug 9, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

When defining a service with an id that is also a class name, you might have an error message like Class “” used for service “\App\Some\Service” cannot be found. if your is starts with a backslash.

The new error message is now hopefully less cryptic: Service definition "\App\Some\Service" has no class, and its name looks like a FQCN but it starts with a backslash; remove the leading backslash.

@fabpot fabpot merged commit 3647cca into symfony:4.3 Aug 9, 2019
fabpot added a commit that referenced this pull request Aug 9, 2019
This PR was merged into the 4.3 branch.

Discussion
----------

[DependencyInjection] Improve an exception message

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

When defining a service with an id that is also a class name, you might have an error message like `Class “” used for service “\App\Some\Service” cannot be found.` if your is starts with a backslash.

The new error message is now hopefully less cryptic: `Service definition "\App\Some\Service" has no class, and its name looks like a FQCN but it starts with a backslash; remove the leading backslash.`

Commits
-------

3647cca [DependencyInjection] improved exception message
@ro0NL
Copy link
Contributor

ro0NL commented Aug 10, 2019

i was curious about doing it in ResolveClassPass (vs. CheckDefinitionValidityPass from #28057)

class Kernel extends BaseKernel implements CompilerPassInterface
{
    public function process(ContainerBuilder $c)
    {
        dd($c->getDefinition('\\Foo\\Bar'));
    }

this now breaks :) so perhaps target 4.4? Alternatively cant we fix it in 3.4 at a later stage (i.e. during optimization instead of before)?

Maybe this is too much an edge case, but then 3.4 was fine also 😅 (though 4.3 is fairly new). Just wanted to share this :)

nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Aug 10, 2019
…message (fabpot)"

This reverts commit 2f2d1aa, reversing
changes made to 07cf927.
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Aug 10, 2019
…message (fabpot)"

This reverts commit 2f2d1aa, reversing
changes made to 07cf927.
nicolas-grekas added a commit that referenced this pull request Aug 20, 2019
…ption message" (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

Revert "bug #33092 [DependencyInjection] Improve an exception message"

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

As reminded by @ro0NL in #33092 (comment), it looks like we forgot that `CheckDefinitionValidityPass` already checks and suggests for leading slashes.

Why didn't you get the exception from `CheckDefinitionValidityPass` @fabpot?

Commits
-------

ed590ca Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Aug 20, 2019
…ption message" (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

Revert "bug #33092 [DependencyInjection] Improve an exception message"

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

As reminded by @ro0NL in symfony/symfony#33092 (comment), it looks like we forgot that `CheckDefinitionValidityPass` already checks and suggests for leading slashes.

Why didn't you get the exception from `CheckDefinitionValidityPass` @fabpot?

Commits
-------

ed590ca16b Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
nicolas-grekas added a commit that referenced this pull request Aug 20, 2019
* 4.3:
  cs fix
  Fix inconsistent return points.
  [Config] Add handling for ignored keys in ArrayNode::mergeValues.
  Fix inconsistent return points.
  [Security/Core] UserInterface::getPassword() can return null
  [Router] Fix TraceableUrlMatcher behaviour with trailing slash
  Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
nicolas-grekas added a commit that referenced this pull request Aug 20, 2019
* 4.4:
  cs fix
  Fix inconsistent return points.
  [Config] Add handling for ignored keys in ArrayNode::mergeValues.
  Fix inconsistent return points.
  [Security/Core] UserInterface::getPassword() can return null
  cs fix
  cs fix
  Fix missing exporter in PHPUnit constraint poylfill
  added `Process::getLastOutputTime()` method
  [Router] Fix TraceableUrlMatcher behaviour with trailing slash
  [HttpKernel] Remove outdated docblock comment
  Fix handling for session parameters
  Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
@fabpot fabpot mentioned this pull request Aug 26, 2019
@fabpot fabpot deleted the container-better-error-message branch September 6, 2019 10:41
hultberg pushed a commit to hultberg/symfony that referenced this pull request Sep 17, 2021
* 4.3:
  cs fix
  Fix inconsistent return points.
  [Config] Add handling for ignored keys in ArrayNode::mergeValues.
  Fix inconsistent return points.
  [Security/Core] UserInterface::getPassword() can return null
  [Router] Fix TraceableUrlMatcher behaviour with trailing slash
  Revert "bug symfony#33092 [DependencyInjection] Improve an exception message (fabpot)"
hultberg pushed a commit to hultberg/symfony that referenced this pull request Sep 17, 2021
* 4.4:
  cs fix
  Fix inconsistent return points.
  [Config] Add handling for ignored keys in ArrayNode::mergeValues.
  Fix inconsistent return points.
  [Security/Core] UserInterface::getPassword() can return null
  cs fix
  cs fix
  Fix missing exporter in PHPUnit constraint poylfill
  added `Process::getLastOutputTime()` method
  [Router] Fix TraceableUrlMatcher behaviour with trailing slash
  [HttpKernel] Remove outdated docblock comment
  Fix handling for session parameters
  Revert "bug symfony#33092 [DependencyInjection] Improve an exception message (fabpot)"
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.

5 participants