There has been an error processing your request.

Are you sick and tired of scrolling you browser when you get Magento error, trying to read and trace it?
Here is a post of my colleague Ivan Weiler which describes how to enable error information in latest Magento.
This is a screenshot of my browser when I get Magento error:
I don’t need to search for report file and open it in a text editor.
It’s clear and readable.
All you need to do is to little modify error reporting file which is in your:
“/report/skin/default/index.phtml” file.
And you can style it as you wish.
Here is how my “/report/skin/default/index.phtml” file looks like:
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Error Submission Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body class=" customer-account-create">
<div class="middle-container">
<div class="middle col-1-layout">
<div id="main" class="col-main">
<div class="page-head">
<h3>There has been an error processing your request.</h3>
</div>
< ?php if ($action == 'print'): ?>
<div style="padding:10px; border:1px solid #666; background:#EFEFEF;">
<div style="width:100%; overflow:auto;">
<pre>
< ?php echo $reportData[0] ?>
<b>Trace:</b>
< ?php echo $reportData[1] ?>
</pre>
</div>
</div>
< ?php endif; ?>
</div>
</div>
</div>
</body>
</html>
That’s it.
Enjoy tracing and handling Magento errors.
16 comments
hello
I installed the templates hello wired, but does not work and this message:
There Has Been an error processing your request
Exception printing is disabled by default for security reasons.
Error logs record number: 831664191542
Can you help me?
Still can’t solve my magento problem.
If you’re doing development, often times, the backtrace that Magento’s error and exception handlers output simply isn’t good enough. I’d highly recommend the following:
1. Install xdebug in your development environment so that you can get FULL backtraces for exceptions and errors.
2. “Hack” your Magento codebase to let exceptions and errors get handled by the default php handler (which will be xdebug, if it’s installed) when developer mode is turned on. Here’s a blog post explaining that process: http://classyllama.com/development/magento-development/magento-initial-setup/
Um the problem Im having is Admin side.
Open config.xml and set to email and delete if you want to avoid displaying code to the customers when they receive and error.
Then you get a nice tidy email with lots of code 🙂
Can anyone help with this error?
Cannot print anything from Admin/Sales
Notice: iconv() [function.iconv]: Wrong charset, conversion from `UTF-16BE’ to `UTF-8′ is not allowed in /xxxxxxxxx/public/www/lib/Zend/Pdf/Resource/Font.php on line 251
Also don’t forget to enable your error reporting in the admin section – the actual log files saved are quite useful – I used them to sort out a pesky paypal problem – it tells you what went wrong – the error message and also which file and what line caused the exception.
How to enable error reporting If you’re using Magento 1.4 or higher (figured it out : )
simply rename your errors/local.xml.sample to errors/local.xml
By modifying the local.xml you can even enable error reports to be sent to an e-mail address.
@Roy
Yes, it’s true, the report files structure in the article is outdated and changes recommended here wont work for the latest Magento version.
If you want to remove magento logo and some other information from the report page you should modify these files:
– errors/default/page.phtml
– errors/default/css/styles.css
“/report/skin/default/index.phtml” this path doesn’t exist. either you’ve shortened it or it doesn’t exist. using magento 1.4, please advice
Thank you for sharing this knowledge with the blogging world!
@EcommerceDeveloper
Great, thanks! =)
In my previous message all the wight-space characters were trimmed, so patch wont be applied correctly.
Here is step by step changing (replace ‘….’ string with 4 space characters):
1. Open app/Mage.php
2. Find line #755, above it should be something like that:
….public static function getIsDeveloperMode()
….{
……..return self::$_isDeveloperMode;
….}
3. Insert LF at 755 and put /**
…. * Formats exception argument to user friendly string value
…. *
…. * @param mixed $argument
…. * @return string
…. */
….protected static function _formatTraceArgument($argument, $level = 1)
….{
……..if ($argument instanceof Varien_Object) {
…………return print_r($argument->debug(), true);
……..} elseif (is_object($argument)) {
…………return get_class($argument);
……..} elseif (is_array($argument)) {
…………$formatted = array();
…………foreach ($argument as $key => $value) {
…………….$formatted[] = sprintf(“\n%s%s => %s”, str_pad(“\t”, $level), self::_formatTraceArgument($key), self::_formatTraceArgument($value, $level + 1));
…………}
…………return sprintf(“array(%s)”, implode(“,”, $formatted));
……..} elseif (is_bool($argument)) {
…………return ($argument ? ‘true’ : ‘false’);
……..} elseif ($argument === null) {
…………return ‘null’;
……..} elseif (is_string($argument)) {
…………return sprintf(‘”%s”‘, addcslashes((string) $argument, ‘”‘));
……..}
……..return $argument;
….}
…./**
…. * Formats exception trace to user friendly lines without trim of arguments
…. *
…. * @param Exception $exception
…. * @return string
…. */
….protected static function _formatExceptionTrace(Exception $exception)
….{
……..$trace = ”;
……..foreach ($exception->getTrace() as $index => $traceLine) {
…………$argumentsFormated = array();
…………foreach ($traceLine[‘args’] as $argument) {
…………….$argumentsFormated[] = self::_formatTraceArgument($argument);
…………}
…………$trace .= sprintf(“#%d %s(%d): %s(%s)\n”, $index, $traceLine[‘file’], $traceLine[‘line’], (isset($traceLine[‘class’]) ? $traceLine[‘class’] . $traceLine[‘type’] : ”) . $traceLine[‘function’], implode(‘, ‘, $argumentsFormated));
……..}
……..return $trace;
….}
4. Find line 819, there should be something like this “print $e->getTraceAsString();”
5. Replace “print $e->getTraceAsString();” with “print self::_formatExceptionTrace($e);”
6. Find line 827, there should be something like this “$e->getTraceAsString()”
6. Replace “$e->getTraceAsString()” with “self::_formatExceptionTrace($e)”
7. Enjoy it! =)
@m4e:
Also there is more proper way in 1.4.x to set developer mode without changing of index.php and allow to show full error trace only for your IP address:
SetEnvIf Remote_Addr “^123\.123\.123\.123$” MAGE_IS_DEVELOPER_MODE=1
So other users can’t see your secure system paths and creditals.
If you want to change the trace of an error message, you can just apply this patch:
Index: app/Mage.php
===================================================================
— app/Mage.php (revision 1256)
+++ app/Mage.php (working copy)
@@ -753,6 +753,55 @@
}
/**
+ * Formats exception argument to user friendly string value
+ *
+ * @param mixed $argument
+ * @return string
+ */
+ protected static function _formatTraceArgument($argument, $level = 1)
+ {
+ if ($argument instanceof Varien_Object) {
+ return print_r($argument->debug(), true);
+ } elseif (is_object($argument)) {
+ return get_class($argument);
+ } elseif (is_array($argument)) {
+ $formatted = array();
+ foreach ($argument as $key => $value) {
+ $formatted[] = sprintf(“\n%s%s => %s”, str_pad(“\t”, $level), self::_formatTraceArgument($key), self::_formatTraceArgument($value, $level + 1));
+ }
+ return sprintf(“array(%s)”, implode(“,”, $formatted));
+ } elseif (is_bool($argument)) {
+ return ($argument ? ‘true’ : ‘false’);
+ } elseif ($argument === null) {
+ return ‘null’;
+ } elseif (is_string($argument)) {
+ return sprintf(‘”%s”‘, addcslashes((string) $argument, ‘”‘));
+ }
+
+ return $argument;
+ }
+
+ /**
+ * Formats exception trace to user friendly lines without trim of arguments
+ *
+ * @param Exception $exception
+ * @return string
+ */
+ protected static function _formatExceptionTrace(Exception $exception)
+ {
+ $trace = ”;
+ foreach ($exception->getTrace() as $index => $traceLine) {
+ $argumentsFormated = array();
+ foreach ($traceLine[‘args’] as $argument) {
+ $argumentsFormated[] = self::_formatTraceArgument($argument);
+ }
+ $trace .= sprintf(“#%d %s(%d): %s(%s)\n”, $index, $traceLine[‘file’], $traceLine[‘line’], (isset($traceLine[‘class’]) ? $traceLine[‘class’] . $traceLine[‘type’] : ”) . $traceLine[‘function’], implode(‘, ‘, $argumentsFormated));
+ }
+
+ return $trace;
+ }
+
+ /**
* Display exception
*
* @param Exception $e
@@ -767,7 +816,7 @@
}
print $e->getMessage() . “\n\n”;
– print $e->getTraceAsString();
+ print self::_formatExceptionTrace($e);
print ”;
} else {
self::getConfig()->createDirIfNotExists(self::getBaseDir(‘var’) . DS . ‘report’);
@@ -775,8 +824,9 @@
$reportFile = self::getBaseDir(‘var’) . DS . ‘report’ . DS . $reportId;
$reportData = array(
!empty($extra) ? $extra . “\n\n” : ” . $e->getMessage(),
– $e->getTraceAsString()
+ self::_formatExceptionTrace($e)
);
+
if (isset($_SERVER) && isset($_SERVER[‘REQUEST_URI’])) {
$reportData[] = $_SERVER[‘REQUEST_URI’];
}
As I can see, you’ve just removed styles, messages and form?
The same can be done more simply: uncomment in your index.php
Mage::setIsDeveloperMode(true) (for ver. 1.3.2.4)
or comment IF brackets around the call (for ver. 1.4.x)
So Mage::printException() will output just the following:
$e->getMessage()
$e->getTraceAsString()
The commonly needed thing is not to cut method parameters in a trace string.
#0 …. ->addTab(‘tabname’, ‘cata…..’…..)….
Do you know how?
BR, m4e
Didnt it used to do this before in their wisdom they realised displaying stack-traces to general users was insecure.