Skip to content
Browse files

Add ability for JError echo handler to display a backtrace.

If the document body is empty for a custom error page, defer to the echo
handler.
  • Loading branch information...
1 parent 4d9d4f2 commit 3e0bfb5283ea593af3cebab038aebca65041ba93 @eddieajau committed Sep 16, 2011
Showing with 46 additions and 5 deletions.
  1. +46 −5 libraries/joomla/error/error.php
View
51 libraries/joomla/error/error.php
@@ -543,21 +543,54 @@ public static function handleEcho(&$error, $options)
$level_human = JError::translateErrorLevel($error->get('level'));
+ // If system debug is set, then output some more information.
+ if (constant('JDEBUG'))
+ {
+ $backtrace = $error->getTrace();
+ $trace = '';
+ for( $i = count( $backtrace )-1; $i >= 0 ; $i-- )
+ {
+ if (isset($backtrace[$i]['class']))
+ {
+ $trace .= sprintf("\n%s %s %s()", $backtrace[$i]['class'], $backtrace[$i]['type'], $backtrace[$i]['function']);
+ }
+ else
+ {
+ $trace .= sprintf("\n%s()", $backtrace[$i]['function']);
+ }
+
+ if (isset($backtrace[$i]['file']))
+ {
+ $trace .= sprintf(' @ %s:%d', $backtrace[$i]['file'], $backtrace[$i]['line']);
+ }
+ }
+ }
+
if (isset($_SERVER['HTTP_HOST']))
{
// output as html
- echo "<br /><b>jos-$level_human</b>: " . $error->get('message') . "<br />\n";
+ echo "<br /><b>jos-$level_human</b>: "
+ . $error->get('message') . "<br />\n"
+ . (constant('JDEBUG') ? nl2br($trace) : '');
}
else
{
// Output as simple text
if (defined('STDERR'))
{
fwrite(STDERR, "J$level_human: " . $error->get('message') . "\n");
+ if (constant('JDEBUG'))
+ {
+ frwite(STDERR, $trace);
+ }
}
else
{
echo "J$level_human: " . $error->get('message') . "\n";
+ if (constant('JDEBUG'))
+ {
+ echo $trace;
+ }
}
}
@@ -768,11 +801,19 @@ public static function customErrorPage(&$error)
$document->setTitle(JText::_('Error') . ': ' . $error->get('code'));
$data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => $config->get('debug')));
- // Do not allow cache
- JResponse::allowCache(false);
+ // Failsafe to get the error displayed.
+ if (empty($data))
+ {
+ self::handleEcho($error, array());
+ }
+ else
+ {
+ // Do not allow cache
+ JResponse::allowCache(false);
- JResponse::setBody($data);
- echo JResponse::toString();
+ JResponse::setBody($data);
+ echo JResponse::toString();
+ }
}
else
{

0 comments on commit 3e0bfb5

Please sign in to comment.
Something went wrong with that request. Please try again.