Upgrade of template-patches - Yireo

Handling Magento errors

Saturday, 15 May 2010

Magento 1.4 ships with a new feature, which effectively hides errors from your visitors. If some kind of error occurs - a PHP Fatal Error, or PHP Notice Error, or database error - the actual error is written to file and not shown on screen. But when developing Magento sites, this behaviour might actually become annoying. Luckily you can easily re-enable the error-displaying again.

Peeking at the files

When an error occurs, a dump of the error is stored within the Magento folder var/reports. By inspecting those files, you will find the actual error but also a trace of the PHP-code producing the error. Some examples of what this error might contain:

  • SQL-commands containing some kind of error
  • A call to a non-existing PHP-class (perhaps because an extension was removed)
  • Incorrect PHP-variables
All this information is very useful when it comes to debugging problems. On developement sites, it there for becomes kind of annoying, that for every error you need to navigate back to the var/reports folder to inspect the actual error.

Showing errors anyway

Displaying the error on screen is much easier to work with. To enable the error-displaying again (just like with pre-1.4 versions), navigate to the errors-folder in the Magento root, and rename the file local.xml.sample to local.xml. The XML-file should contain a line similar to this:

<config>
    <skin>default</skin>
    <report>
        <action>print</action>
        <trash>leave</trash>
    </report>
</config>

You can see that the action here is configured to print the message on screen, while the original dump is also left on the filesystem (in var/cache). You could also change the XML-code a bit to remove the dump-file instead:

<trash>delete</trash>

Mail me if an error occurs

Even cooler is that the XML-code also allows you to define an email-address to which mail should be sent if some error occurs:

<config>
    <skin>default</skin>
    <report>
        <action>email</action>
        <subject>Whoops, something went wrong in Magento</subject>
        <email_address>info [5a]</email_address>
        <trash>delete</trash>
    </report>
</config>

Those of you who have wondered why errors were displayed using the original skin, can also see that the skin can be changed as well here:

<skin>myskin</skin>

Hope you find this all usefull.

Tags: magento

About Yireo

Yireo tries to help webdevelopers build successful Joomla! and Magento sites.

More about Yireo