22

Anyone know how do you make Magento show the full error message and not truncate it with ...

example:

Warning: include() [function.include]: Filename cannot be empty  in /home/kevinmag/public_html/app/code/core/Mage/Core/Block/Template.php on line 241

0 /home/kevinmag/public_html/app/code/core/Mage/Core/Block/Template.php(241): mageCoreErrorHandler(2, 'include() [fetchView('frontend/base/d...')

I want to know what the [fetchView('frontend/base/d...') it cutting off with the ...

Kevin Chavez
  • 445
  • 1
  • 4
  • 16

3 Answers3

30

Don't blame Magento, it's all PHP's fault :) The Exception::getTraceAsString native method cuts the backtrace output, and it seems there's no normal way to handle it.

The only solution I've got to work is next:

  1. I've added a function, which I got from kind sir Steve (How can I get the full string of PHP’s getTraceAsString()) to app\code\core\Mage\Core\functions.php:

    function getExceptionTraceAsString($exception) {
        $rtn = "";
        $count = 0;
        foreach ($exception->getTrace() as $frame) {
            $args = "";
            if (isset($frame['args'])) {
                $args = array();
                foreach ($frame['args'] as $arg) {
                    if (is_string($arg)) {
                        $args[] = "'" . $arg . "'";
                    } elseif (is_array($arg)) {
                        $args[] = "Array";
                    } elseif (is_null($arg)) {
                        $args[] = 'NULL';
                    } elseif (is_bool($arg)) {
                        $args[] = ($arg) ? "true" : "false";
                    } elseif (is_object($arg)) {
                        $args[] = get_class($arg);
                    } elseif (is_resource($arg)) {
                        $args[] = get_resource_type($arg);
                    } else {
                        $args[] = $arg;
                    }
                }
                $args = join(", ", $args);
            }
            $rtn .= sprintf( "#%s %s(%s): %s%s(%s)\n",
                $count,
                $frame['file'],
                $frame['line'],
                isset($frame['class']) ? $frame['class'] . '->' : '',
                $frame['function'],
                $args );
            $count++;
        }
        return $rtn;
    }
    
  2. I've modified Mage.php file (printException method) - instead of $e->getTraceAsString() I've inserted getExceptionTraceAsString($e) - notice that there's two appearances: for Debug mode on, and off.

To demonstrate the results, here is an example of two backtraces - without the fix, and with the fix accordingly.

Old:

0 C:\apache\htdocs\checkout\lib\Varien\Db\Statement\Pdo\Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
1 C:\apache\htdocs\checkout\lib\Zend\Db\Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
2 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
3 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT COUNT(DI...', Array)
4 C:\apache\htdocs\checkout\lib\Varien\Db\Adapter\Pdo\Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('SELECT COUNT(DI...', Array)
5 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Abstract.php(825): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
6 C:\apache\htdocs\checkout\lib\Varien\Data\Collection\Db.php(217): Zend_Db_Adapter_Abstract->fetchOne(Object(Varien_Db_Select), Array)
7 C:\apache\htdocs\checkout\lib\Varien\Data\Collection.php(225): Varien_Data_Collection_Db->getSize()
8 C:\apache\htdocs\checkout\lib\Varien\Data\Collection.php(211): Varien_Data_Collection->getLastPageNumber()
9 C:\apache\htdocs\checkout\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(996): Varien_Data_Collection->getCurPage()
10 C:\apache\htdocs\checkout\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(831): Mage_Eav_Model_Entity_Collection_Abstract->_loadEntities(false, false)
11 C:\apache\htdocs\checkout\app\code\core\Mage\Review\Model\Observer.php(78): Mage_Eav_Model_Entity_Collection_Abstract->load()
12 C:\apache\htdocs\checkout\app\code\core\Mage\Core\Model\App.php(1299): Mage_Review_Model_Observer->catalogBlockProductCollectionBeforeToHtml(Object(Varien_Event_Observer))
13 C:\apache\htdocs\checkout\app\code\core\Mage\Core\Model\App.php(1274): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Review_Model_Observer), 'catalogBlockPro...', Object(Varien_Event_Observer))
14 C:\apache\htdocs\checkout\app\Mage.php(416): Mage_Core_Model_App->dispatchEvent('catalog_block_p...', Array)

New:

0 C:\apache\htdocs\checkout\lib\Varien\Db\Statement\Pdo\Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
1 C:\apache\htdocs\checkout\lib\Zend\Db\Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
2 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
3 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT COUNT(DISTINCT e.entity_id) FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='3' AND cat_index.is_parent=1
 INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 WHERE (d=1) AND (d=1)', Array)
4 C:\apache\htdocs\checkout\lib\Varien\Db\Adapter\Pdo\Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('SELECT COUNT(DISTINCT e.entity_id) FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='3' AND cat_index.is_parent=1
 INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 WHERE (d=1) AND (d=1)', Array)
5 C:\apache\htdocs\checkout\lib\Zend\Db\Adapter\Abstract.php(825): Varien_Db_Adapter_Pdo_Mysql->query(Varien_Db_Select, Array)
6 C:\apache\htdocs\checkout\lib\Varien\Data\Collection\Db.php(217): Zend_Db_Adapter_Abstract->fetchOne(Varien_Db_Select, Array)
7 C:\apache\htdocs\checkout\lib\Varien\Data\Collection.php(225): Varien_Data_Collection_Db->getSize()
8 C:\apache\htdocs\checkout\lib\Varien\Data\Collection.php(211): Varien_Data_Collection->getLastPageNumber()
9 C:\apache\htdocs\checkout\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(996): Varien_Data_Collection->getCurPage()
10 C:\apache\htdocs\checkout\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(831): Mage_Eav_Model_Entity_Collection_Abstract->_loadEntities(false, false)
11 C:\apache\htdocs\checkout\app\code\core\Mage\Review\Model\Observer.php(78): Mage_Eav_Model_Entity_Collection_Abstract->load()
12 C:\apache\htdocs\checkout\app\code\core\Mage\Core\Model\App.php(1299): Mage_Review_Model_Observer->catalogBlockProductCollectionBeforeToHtml(Varien_Event_Observer)
13 C:\apache\htdocs\checkout\app\code\core\Mage\Core\Model\App.php(1274): Mage_Core_Model_App->_callObserverMethod(Mage_Review_Model_Observer, 'catalogBlockProductCollectionBeforeToHtml', Varien_Event_Observer)
14 C:\apache\htdocs\checkout\app\Mage.php(416): Mage_Core_Model_App->dispatchEvent('catalog_block_product_list_collection', Array)

Update: the above logic only modified Error/report output; to add this logic to Exception log as well you'll want to modify the Mage::logException method - change

self::log("\n" . $e->__toString(), Zend_Log::ERR, $file);

with

self::log("\n" . $e->getMessage() . getExceptionTraceAsString($e), Zend_Log::ERR, $file);

Hope it helps!

Community
  • 1
  • 1
Slayer Birden
  • 3,664
  • 2
  • 22
  • 29
  • 4
    Maybe you should credit the original author of this answer ?: http://stackoverflow.com/questions/1949345/how-can-i-get-the-full-string-of-phps-gettraceasstring – Marty Wallace Sep 10 '12 at 20:04
  • 1
    Thanks for pointing it out @user1189880! I've found the code in the old project of mine, and totally forgot where I've got it from. I've updated the post to credit Steve. – Slayer Birden Sep 10 '12 at 20:19
  • Its a good workaround to *temporarily* debug, of course. I'm having troubles with constraints violations, but it didn't helps too much since it doesnt shows the real values executed in the query (only ? is shown because of the prepared statements). – Ricardo Martins Apr 19 '13 at 14:08
  • This kinda did not work for me, Mage was telling me, I was calling an "undefined function getExceptionTraceAsString()". So I added it to Mage.php directly within the class as `public function` and called it inside `printException` with `self::getExceptionTraceAsString($e)` – rob_st Jul 07 '16 at 09:07
  • **Edit:** I stumpled across a custom `functions.php` in `app/code/local/Mage/Core` which is overriding the default file (as it is supposed to). I added the `getExceptionTraceAsString()`-function there and everything is fine. So everyone else out there, make sure to check if you already have a custom `functions.php` – rob_st Jul 07 '16 at 12:49
2

This is PHP and not Magento.

See here where the truncation is happening - https://github.com/php/php-src/blob/master/Zend/zend_exceptions.c#L383

I'd personally just live with it and use other debugging methods as opposed to hacking core files :)

Drew Hunter
  • 10,136
  • 2
  • 40
  • 49
  • 6
    hacking core is bad, but being blind with random exceptions popping out on production is worse... if PHP is not providing us with normal solutions, we need to use hacks – Slayer Birden Sep 10 '12 at 20:31
  • 1
    It would help to share what "other debugging methods" are there to use. – Meetai.com Jun 28 '14 at 08:35
-5

You can do it just by simple change in your file.

Just open you index.php present on the root folder and write the following line just after the starting tag of the <?php error_reporting(E_ALL);

After this save and upload your file and clear the cache and now all errors will be displayed.

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
Yogesh Pawar
  • 336
  • 2
  • 17