Magento: Directly output any errors or notices - debugging

In my module's code, I echo'd an undefined variable:
echo $doesnotexist;
I have done the following in index.php:
error_reporting(E_ALL);
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
This combination shows a "Whoops, our bad..." 404 type page when the code is executed. And in the exception.log there is a Notice ("Undefined variable: doesnotexist") as well as a stack trace.
If I remove part of the instructions in index.php:
error_reporting(E_ALL);
//Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
The frontend shows the page normally without any indication of the error, and the error is logged to system.log.
Now my question is: Is there a way to output these notices/errors directly to the frontend? Or am I supposed to always keep open a copy of system.log or exception.log while coding?

Magento normally uses zend exception/error handling class for the error and exception handling. So for the errors in which magento code send exception is logged in your log.
But if the error is not catchable by magento then it will be printed on your page.
You can get your error on frontend in 2 case:
If you are creating your own magento extension then you can throw your error in the way so that it can get displayed on magento page
If you are working on .phtml file and getting fatal errors

As a security concern errors and warning s should not be displayed on front end.
If there is an exception or you do some system log you will be able to get that from system.log or exception.log
For PHP errors you should refer to error log file that is generated at site level.
Mage::setIsDeveloperMode(true); can be used only after you have included Mage.php so paste your complete index.php code

Related

magento custom theme error

trying to create a custom theme with bitnami XAMPP using magento devdocs
https://devdocs.magento.com/guides/v2.2/frontend-dev-guide/themes/theme-create.html
I get this error when I try to access the admin panel
There has been an error processing your request
Exception printing is disabled by default for security reasons.
Error log record number: 1130478184
I think you have to first check in your error log number "1130478184" where you exactly know what is the issue. I think from your given link which you refer your issue must be occured from theme.xml file's <preview_image>media/preview.jpg</preview_image> line. You have to try with comment following code in theme.xml file:-
<!--media>
<preview_image>media/preview.jpg</preview_image>
</media-->

Lampp does not show the cause of error

I am working on php files, but when there is an error, it does not tell me the cause or the number of line containing the error, only there is a message on the page" the localhost page isn't working"
At the top of your PHP file, put
error_reporting(E_ALL);
ini_set('display_errors', 1);
When you are in dev mode. When you are done w/ development, take it back out or comment it.

Not able to add products on magento HTTP ERROR 500

Getting error on my magento website.
HTTP ERROR 500 on adding products.
Attached my error log files.
[16-Feb-2017 09:19:24 UTC] PHP Fatal error: Call to a member function getResourceCollection() on a non-object in /home/allinoll/public_html/smnutritions.com/includes/src/Mage_Catalog_Model_Product_Attribute_Source_Countryofmanufacture.php on line 48
Issues Fixed. I just deleted all the files from includes except config.php and htaccess and now its working perfectly even performance also improved.

Opencart Ajax Error unexpected token <

I'm using OpenCart 1.5.1.3 and having this strange error on Guest Shipping in Ajax. I'm getting the error "Unexpected token <".
I have tried everyting, change the Ajax code, look at the controller, but no luck. You can try it yourself at http://www.biancabonte.nl/shop/. Put something in the cart and checkout Direct instead of registering. Then the problem occurs.
Thanks
This is almost certainly due to an error message being output by your store, which precedes the AJAX JSON content. Check your error logs around the time you made/make the request. While they won't contain the < character since they're not formatted like the ones output by PHP, they will still have the actual message. Your error logs will either be in the SYSTEM > ERROR LOGS in the admin, or in your cpanel/plesk/other control panel under logs usually

Redirecting errors in codeigniter

I want all codeigniter errors to be redirected to a custom error page. I have redirected 404 errors with $route['404_override'] = 'errorcontroller'; How can I redirect all the other errors such as db and php
You can always use try and catch block and then redirect to your custom error page. But as per your questions, there are some things you should consider.
Redirect will issue a completely new request which is accomplished with the header sent to the browser. For that reason you will not be able to display the error message unless you save that message in session or something.
Some errors results in PHP throwing exceptions while others don't. Some DB interactions error only raises PHP warnings or error. PHP execution may halt but no exception will be thrown. In such case even wrapping the code in try catch will not be any help. However, you can create a custom error handler and inform PHP to use that handler. Then in the custom error handler you are free to throw exceptions or redirect to error page.
you can also use .htaccess to force redirection to the pages you set at specific header codes [404,304,500] etc
Hope this helps!

Resources