Magento 如何显示完整的错误消息而不是截断一个

标签 magento

任何人都知道如何让 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...') 它与 ...

最佳答案

不要责怪 Magento,这都是 PHP 的错 :) Exception::getTraceAsString native 方法削减了回溯输出,似乎没有正常的方法来处理它。

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

  • 我添加了一个功能,我从善良的先生 那里得到的Steve ( How can I get the full string of PHP’s 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;
    }
    
  • 我修改了 Mage.php 文件(printException 方法) - 而不是 $e->getTraceAsString()我已插入 getExceptionTraceAsString($e) - 注意有两种外观: Debug模式打开和关闭。

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

    老的:
    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);
    

    希望能帮助到你!

    关于Magento 如何显示完整的错误消息而不是截断一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12356260/

    相关文章:

    mysql - SQLSTATE[HY000] : General error: 2006 MySQL server has gone away on running cron job magento

    css - Magento 自定义 css 被父 css 覆盖 - 使用 local.xml

    magento - 如何使用magmi在magento中导入?

    magento - 在magento中制作不需要的电子邮件地址

    collections - 自定义产品集合上的 Magento 分层导航

    mysql - Magento - 如何按最大值选择mysql行?

    php - 特定国家/地区的 Magento 产品

    magento - 从 getChildrenCategories() 获取缩略图 URL

    php - Cron 不会停止运行

    php - Magento连接查询使用3张表进行查询