-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Ignore AnnotationException exceptions in the AnnotationsCacheWarmer #20959
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
Coding standard issues are unrelated to my change, should I still apply them ? |
@@ -75,6 +76,8 @@ public function warmUp($cacheDir) | |||
$this->readAllComponents($reader, $class); | |||
} catch (\ReflectionException $e) { | |||
// ignore failing reflection | |||
} catch (AnnotationException $e) { | |||
|
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.
You should add a comment explaining why
@fabpot I added a short explanation and a link that reference this PR. Also I will ask again, should I apply the suggested coding standard changes even if they are not related to my code ? |
@fancyweb No, please ignore them. |
* environment but is always added to the annotations.map file by some Symfony default behaviors, | ||
* and you always end up with a not found Annotation. | ||
* | ||
* cf https://github.com/symfony/symfony/pull/20959 for a longer explanation. |
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 removed, we don't add links to github: the git history (git blame) should have everything instead (which it has)
Isn't this a bug fix? |
Thank you @fancyweb. |
… the AnnotationsCacheWarmer (fancyweb) This PR was squashed before being merged into the 3.2 branch (closes #20959). Discussion ---------- [FrameworkBundle] Ignore AnnotationException exceptions in the AnnotationsCacheWarmer | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I ran into a case that led to an `AnnotationException` in the `AnnotationsCacheWarmer`. I deduced that these exceptions should be ignored to not break the cache warming process. The case : * You have a controller in your `AppBundle\Controller\` directory. * You have an annotation in this controller that will never be found (because you made a mistake in the class / annotation name) or not every time : for example your controller is only used in dev env and it uses an annotation that is defined in a vendor bundle that is only under the `require-dev` key in your `composer.json` because you don't need it in your production deployment. So in production, your controller exists but will never be used. However the vendor bundle does not exist. * You dump your autoload files with composer using the `--optimize` option. * You end up with an `AnnotationException`. Why : * In the [`FrameworkExtension`](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L189), the `**Bundle\Controller\` pattern is added as an "annotated class to compile". * In the [`AddClassesToCachePass`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/DependencyInjection/AddClassesToCachePass.php#L50), all the classes defined in the `autoload_classmap.php` file are matched against the previous pattern. * Your controller will match. So even if you don't use it at all in your application, the annotation will still be read and the exception will be thrown. Commits ------- 6749569 [FrameworkBundle] Ignore AnnotationException exceptions in the AnnotationsCacheWarmer
Yes it is :) |
Sorry, I missed the fact that the class wasn't present in 3.1. |
I ran into a case that led to an
AnnotationException
in theAnnotationsCacheWarmer
. I deduced that these exceptions should be ignored to not break the cache warming process.The case :
AppBundle\Controller\
directory.require-dev
key in yourcomposer.json
because you don't need it in your production deployment. So in production, your controller exists but will never be used. However the vendor bundle does not exist.--optimize
option.AnnotationException
.Why :
FrameworkExtension
, the**Bundle\Controller\
pattern is added as an "annotated class to compile".AddClassesToCachePass
, all the classes defined in theautoload_classmap.php
file are matched against the previous pattern.