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 ...
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:
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;
}
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!
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With