22

任何人都知道如何让 Magento 显示完整的错误消息,而不是用...截断它

例子:

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...')

我想知道 [fetchView('frontend/base/d...') 它与 ...

4

3 回答 3

29

不要责怪 Magento,这都是 PHP 的错 :) Exception::getTraceAsString本机方法会切断回溯输出,似乎没有正常的方法来处理它。

我必须工作的唯一解决方案是下一个:

  1. 我添加了一个函数,我从好心的Steve先生(我如何获取 PHP 的 getTraceAsString() 的完整字符串)到 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. 我已经修改了 Mage.php 文件(printException方法) - 而不是$e->getTraceAsString()我已经插入getExceptionTraceAsString($e)- 请注意有两种外观:打开和关闭调试模式。

为了演示结果,这里是两个回溯的示例 - 没有修复,并且有相应的修复。

老的:

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)

新的:

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)

更新:以上逻辑只修改了错误/报告输出;要将此逻辑添加到异常日志中,您还需要修改 Mage::logException 方法 - 更改

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

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

希望能帮助到你!

于 2012-09-10T19:49:12.327 回答
2

这是 PHP 而不是 Magento。

在此处查看发生截断的位置 - https://github.com/php/php-src/blob/master/Zend/zend_exceptions.c#L383

我个人只是忍受它并使用其他调试方法而不是破解核心文件:)

于 2012-09-10T20:24:57.550 回答
-5

您只需更改文件即可。

index.php只需在根文件夹中打开您当前的内容,然后在<?php error_reporting(E_ALL);

在此保存并上传您的文件并清除缓存后,现在将显示所有错误。

于 2013-01-23T11:06:32.750 回答