-
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
Throw exception for invalid (missing) template in dev mode #8119
Throw exception for invalid (missing) template in dev mode #8119
Conversation
In developer mode php notices/warnings etc are promoted to being exceptions. This means the developer is a bit more diligent with cleaning up any messes as they occur. I noticed this error on a Magento 1 client which is filled with "Not valid template file", I checked in M2 and this error seems to persist. This change should make sure developers do not lead any dead templates in their layout.xml.
$errorMessage = "Invalid template file: '{$templatePath}' in module: '{$this->getModuleName()}'" | ||
. " block's name: '{$this->getNameInLayout()}'"; | ||
if ($this->_appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) { | ||
throw new \InvalidArgumentException($errorMessage); |
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.
Please use \Magento\Framework\Exception\ValidatorException
instead
@convenient Thanks for the contribution, it definitely makes sense to output exception rather way for the developer so there is insensitive to fix it. Added comment to the code review, please process. |
Updates pushed, @vrann Is that alright mate? |
@convenient perfect, thanks! |
Awesome thanks @vrann. I wonder how much screaming there is going to be
|
@convenient wait, what was the intent of PR? Checking
|
@convenient or is that exactly what happens when you leave the dead template in the layout? Yeah, then we might hear boos :) (in developer mode only) |
I meant the latter. I'm wondering how many dead templates exist in m2 websites today, quietly logging away never being cleaned up. We'll find out when this is released and the developers start to complain I guess. |
@convenient thank you for your contribution |
In developer mode php notices/warnings etc are promoted to being exceptions. This means the developer is a bit more diligent with cleaning up any messes as they occur. This does not seem to apply to layout declarations with invalid templates.
I noticed this error on a Magento 1 client which is filled with "Not valid template file", I checked in M2 and this error seems to persist. Developer mode does not promote invalid template errors to being an exception.
This change should make sure developers do not leave any dead templates in their layout.xml. It seems like an easy win to me.
Don't we all want clean log files? :)