Viewing Error Backtraces for Ambiguous Error Messages
There are many times when working with the Magento frontend that I get very ambiguous error message. Here is a screenshot of the type of error I’m talking about:
I usually just search the entire codebase for the error message code, locate the place where the exception is getting caught, and then temporarily modify the code to Mage::log() the following data: $e->getMessage(), $e->getTraceAsString(), etc…
I just came across an exception handler in the Mage_Checkout_MultishippingController class that passed the generic exception message as well as the Exception class itself to Mage::getSingleton(’checkout/session’)->addException(). Here’s the code (from line 219 of the containing file):
catch (Exception $e) { Mage::getSingleton('checkout/session')->addException( $e, Mage::helper('checkout')->__('Data saving problem') ); $this->_redirect('*/*/addresses'); } |
I dug into the Mage::getSingleton(’checkout/session’)->addException() class and realized that it logged the exception code to the var/logs/exception.log file (it only logs the exception if logging is enabled in System > Preferences > Developer). This means that instead of locating and hacking up core files to see exceptions that are thrown, in a lot of cases, you can just monitor the contents of the exception.log file.
If you’re developing on a Mac machine, you can monitor the contents of the exception.log file using the Console app. If you’re on a Linux box, you can use “tail -f var/log/exception.log” to monitor the contents of this file.
Hopefully this helps you in your debugging efforts!
This entry was posted on Friday, March 19th, 2010 at 3:10 pm and is filed under Magento Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
April 20th, 2010 at 9:35 pm
Sweet, I have been doing it the way you have been before finding out about the logging. I even have breakpoints on some catch blocks in the Zend files for certain DB errors that I get that come back ambiguous. I am going to love this.
April 22nd, 2010 at 10:32 am
@Dan – What are you using for your debugging setup? We use PDT + Xdebug for backend development and TextMate for theme development. Using Xdebug (over Zend Debugger) gives us awesome Exception/Error backtraces, as you can read about in this article.
May 10th, 2010 at 2:06 pm
Didn’t know you replied, wonder if there is something you can have where it will email me if someone posts a comment. I always like that, otherwise I forget to go back and look.
I use Netbeans for Magento, themes as well but I use CSS Edit. I also use Textmate but for some reason on Magento I use Netbeans for HTML, but I am not doing a lot of static buildout, if I was just doing html/css probably would use Textmate and CSSEdit. I use Xdebug for degugging. I just haven’t got around to putting in your updates.
May 12th, 2010 at 6:09 pm
@Dan – I’ve added the http://txfx.net/wordpress-plugins/subscribe-to-comments/ plugin to our WP install. Thanks for that suggestion.
I’ve never used NetBeans. Last time I compared it to PDT/Zend Studio, I wasn’t too impressed. I’ll have to check it out again.
May 12th, 2010 at 7:58 pm
I only used it because when first setting up Magento, I had problems setting up my project in Eclipse but it was pretty simple in Netbeans. I am sure it is just as simple in Eclipse but I had some weird issue I can’t remember. I used Eclipse before, for Java work, but mainly used Intellij Idea which I love. I am not sure how good their PHP plugin is but I haven’t seen much about it.
We have developers that use Eclipse and they seem pretty close to me, Although SVN was built in for me and I know they had to install a plugin.