-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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' : ''); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
.
Thank you @jvasseur, comments addressed. Do you confirm it fixes your issue? |
6d5d18a
to
40fe7cd
Compare
There was a problem hiding this 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.
@nicolas-grekas could you add a test for that? |
Test added. |
40fe7cd
to
f2231b5
Compare
Thank you @nicolas-grekas. |
…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
As reported by @jvasseur, confirmation + review welcome.