-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adding Definition::addError() and a compiler pass to throw errors as exceptions #24290
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
0a55740
to
f882813
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.
nice :)
@@ -11,6 +11,8 @@ | |||
|
|||
namespace Symfony\Component\DependencyInjection\Compiler; | |||
|
|||
@trigger_error('The '.__NAMESPACE__.'\AutowireExceptionPass class is deprecated since version 3.4 and will be removed in 4.0. Use the DefinitionErrorExceptionPass class instead.', E_USER_DEPRECATED); |
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.
missing annotation on the class
*/ | ||
public function __construct($throwOnAutowireException = true) | ||
{ | ||
$this->throwOnAutowiringException = $throwOnAutowireException; | ||
} | ||
|
||
/** | ||
* @deprecated |
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.
since version 3.4, to be removed in 4.0
@@ -35,10 +42,19 @@ protected function processValue($value, $isRoot = false) | |||
foreach ($value->getArguments() as $k => $v) { | |||
if ($k !== $i++) { | |||
if (!is_int($k)) { | |||
throw new RuntimeException(sprintf('Invalid constructor argument for service "%s": integer expected but found string "%s". Check your service definition.', $this->currentId, $k)); | |||
$value->addError(sprintf('Invalid constructor argument for service "%s": integer expected but found string "%s". Check your service definition.', $this->currentId, $k)); |
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.
dedup the msg with a var? (same below)
ecd0fbb
to
33d38f7
Compare
Good suggestions! They're all handled :) |
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.
last comments :)
@@ -1090,7 +1093,7 @@ public function setFoo(Foo $foo) | |||
// should be called | |||
} | |||
|
|||
/** @inheritdoc*/ | |||
/** {@inheritdoc}*/ |
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.
should be reverted, a fabbot false-positive
unrelated: InlineServiceDefinitionsPass::getInlinedServiceIds() should be deprecated also
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Throws autowire exceptions from AutowirePass for definitions that still exist. | ||
* | ||
* @deprecated AutowireExceptionPass is deprecated since version 3.4 and will be removed in 4.0. |
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.
@deprecated since version 3.4, will be removed in 4.0.
Tests pass, fabbot failure is false! Should be ready to go :) |
Thank you @weaverryan. |
…hrow errors as exceptions (weaverryan) This PR was squashed before being merged into the 3.4 branch (closes #24290). Discussion ---------- Adding Definition::addError() and a compiler pass to throw errors as exceptions | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes & no | New feature? | yes | BC breaks? | no | Deprecations? | yes (very minor) | Tests pass? | yes | Fixed tickets | #23606 | License | MIT | Doc PR | Not needed Hi guys! Very simple: when there is an error with a Definition, we can now call `Definition::addError()` instead of throwing an exception. Then, a new compiler pass (after removal) actually throws an exception. The advantage is that we can avoid throwing exceptions for services that are ultimately removed from the container. That's important for auto-registration, where we commonly register all services in `src/`... but then many of them are removed later. A few interesting notes: - We can probably convert more things from exceptions to `Definition::addError()`. I've only converted autowiring errors and things in `CheckArgumentsValidityPass` (that was necessary because it was throwing exceptions in some cases due to autowiring failing... which was the true error) - `Definition` can hold multiple errors, but I'm only showing the first error in the exception message. The reason is clarity: I think usually the first error is the most (or only) important. But having `Definition::addError()` avoids the possibility of a later error overriding an earlier one Cheers! Commits ------- a85b37a Adding Definition::addError() and a compiler pass to throw errors as exceptions
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Fix missing CHANGELOG update + typo | Q | A | ------------- | --- | Branch? | 3.4 <!-- see comment below --> | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #24290 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Commits ------- f9aeee5 [DI] Fix missing CHANGELOG update + typo
This PR was merged into the 4.0-dev branch. Discussion ---------- [DI] Remove AutowireExceptionPass | Q | A | ------------- | --- | Branch? | master <!-- see comment below --> | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | yes | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #24290 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Commits ------- 2ada558 [DI] Remove AutowireExceptionPass
Hi guys!
Very simple: when there is an error with a Definition, we can now call
Definition::addError()
instead of throwing an exception. Then, a new compiler pass (after removal) actually throws an exception. The advantage is that we can avoid throwing exceptions for services that are ultimately removed from the container. That's important for auto-registration, where we commonly register all services insrc/
... but then many of them are removed later.A few interesting notes:
Definition::addError()
. I've only converted autowiring errors and things inCheckArgumentsValidityPass
(that was necessary because it was throwing exceptions in some cases due to autowiring failing... which was the true error)Definition
can hold multiple errors, but I'm only showing the first error in the exception message. The reason is clarity: I think usually the first error is the most (or only) important. But havingDefinition::addError()
avoids the possibility of a later error overriding an earlier oneCheers!