-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
magento/magento2#20773: Do not throw exception during autoload #20950
magento/magento2#20773: Do not throw exception during autoload #20950
Conversation
Hi @Vinai. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
Hey @Vinai , since autoloader registration happens before the objectmanager is fully initialized in \Magento\Framework\App\ObjectManagerFactory::create, it now (ironically) throws an exception during the construction of the autoloader. Instead you would have to manually create the logger instance and inject it here \Magento\Framework\ObjectManager\DefinitionFactory::createClassDefinition Not sure how complicated it is to initialize the logger without the OM. Unfortunately I did not find it in any of the calling classes to maybe pass it through. Just another thing: Wouldn't it be more helpful (even if it's nor psr4 compliant) to keep the exceptions at least in developer mode so they are just displayed directly instead of "hidden" in a log file? |
He, stupid of me, sorry. The contribution day ended so I ran out of time to test it. |
3e78c3a
to
ce91cc1
Compare
This was a typical case of Unit Tests green, missing integration tests. |
721c8ac
to
7ab3ee4
Compare
@davidverholen I decided against letting the exception bubble up in developer mode, because that still would prohibit using another autoloader later in the autoloader chain (which is the original reason for the PR). Instead, the code now just tries to log the message if the |
Hi @davidverholen, thank you for the review. |
7ab3ee4
to
0a82094
Compare
Thanks for reviewing, @davidverholen! I just noticed some typos and couldn't resist fixing them and updating the PR. Sorry if that means you have to repeat the review - at least it's a small patch. |
*/ | ||
private function getTestFrameworkObjectManager() | ||
{ | ||
return ObjectManager::getInstance(); |
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.
Could you please inline this method? I don't see how it improves readability and also ObjectManager::getInstance()
is used as is at least once.
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.
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.
Apropos: I should make a PR to fix the return annotation on getInstance
on the test framework ObjectManager - this has been annoying me for 2.5 years now.
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.
@Vinai yep, there is no need to bloat each single test.
dev/tests/integration/testsuite/Magento/Framework/Code/Generator/AutoloaderTest.php
Outdated
Show resolved
Hide resolved
/** | ||
* @after | ||
*/ | ||
public function removeLoggerTestDouble(): void |
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.
Maybe just call them setUp
/tearDown
? Why public?
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 prefer not to override parent class methods. The @before
and @after
annotations on public methods with descriptive names are preferable.
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.
Such name does not add any value compared to just setUp
. I have nothing against such annotations in general but then we should make it an official recommendation, otherwise the code become inconsistent.
dev/tests/integration/testsuite/Magento/Framework/Code/Generator/AutoloaderTest.php
Outdated
Show resolved
Hide resolved
010a9ac
to
d45eded
Compare
d45eded
to
cab38a2
Compare
Hi @sivaschenko, thank you for the review. |
I think the failing test is unrelated to this PR. |
Hi @Vinai, thank you for your contribution! |
@Vinai LOOOL :) Thanks for pointing out, I'll pass it to EngCom guys. |
The same survey app is used for devdoc PRs, too, by the way. |
Description (*)
Avoid uncaught exceptions during autoloading. PSR-4 dictates that must not happen. Return false instead.
Instead, try to log the exception message.
Fixed Issues (if relevant)
#20773
Manual testing scenarios (*)
Run
class_exists(FooFactory::class);
.More information to reproduce the problem is in the issue thread.
Contribution checklist (*)