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:
Error Message

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!

5 Responses to “Viewing Error Backtraces for Ambiguous Error Messages”

  1. 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.

  2. @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.

  3. 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.

  4. @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.

  5. 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.

Comment Form

For Code: Use the html code for < & >.  i.e. "&lt;YOUR_TAG&gt; ...your code... &lt;/YOUR_TAG&gt;"

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Call us at 417-597-3397, email us at sales@classyllama.com, or use this form to contact us:

  1. (required)
  2. (required)
 

cforms contact form by delicious:days

Full builds (design and development) start at $70k