Skip to content

[DI] Display previous error messages when throwing unused bindings #27191

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
May 12, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 7, 2018

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

As reported by @jvasseur, confirmation + review welcome.

throw new InvalidArgumentException(sprintf('Unused binding "%s" in service "%s".', $key, $serviceId));
$message = sprintf('Unused binding "%s" in service "%s".', $key, $serviceId);
if ($this->errors) {
$message .= sprintf("\nCould be related to%s:", 1 < \count($errors) ? ' one of' : '');
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be $this->errors

if ($this->errors) {
$message .= sprintf("\nCould be related to%s:", 1 < \count($errors) ? ' one of' : '');
}
foreach ($this->errors as $serviceId => $mesage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if the missing s is voluntary here, but we can't use $message since it's used in the parent scope, maybe $error ?

$message .= sprintf("\nCould be related to%s:", 1 < \count($errors) ? ' one of' : '');
}
foreach ($this->errors as $serviceId => $mesage) {
$message .= sprintf("\n - \"%s\": %s", $serviceId, $message);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to put the service id here since it's already in the exception message thrown by getConstructor.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented May 8, 2018

Thank you @jvasseur, comments addressed. Do you confirm it fixes your issue?

Copy link
Contributor

@jvasseur jvasseur left a comment

Choose a reason for hiding this comment

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

This works at solving the issue.

@sroze
Copy link
Contributor

sroze commented May 9, 2018

@nicolas-grekas could you add a test for that?

@nicolas-grekas
Copy link
Member Author

Test added.

@fabpot
Copy link
Member

fabpot commented May 12, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit f2231b5 into symfony:3.4 May 12, 2018
fabpot added a commit that referenced this pull request May 12, 2018
…bindings (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Display previous error messages when throwing unused bindings

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

As reported by @jvasseur, confirmation + review welcome.

Commits
-------

f2231b5 [DI] Display previous error messages when throwing unused bindings
@nicolas-grekas nicolas-grekas deleted the di-bind-error branch May 16, 2018 14:51
This was referenced May 21, 2018
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