Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 3e0bfb5283ea593af3cebab038aebca65041ba93 1 parent 4d9d4f2
Andrew Eddie authored

Showing 1 changed file with 46 additions and 5 deletions. Show diff stats Hide diff stats

  1. +46 5 libraries/joomla/error/error.php
51 libraries/joomla/error/error.php
@@ -543,10 +543,35 @@ public static function handleEcho(&$error, $options)
543 543
544 544 $level_human = JError::translateErrorLevel($error->get('level'));
545 545
  546 + // If system debug is set, then output some more information.
  547 + if (constant('JDEBUG'))
  548 + {
  549 + $backtrace = $error->getTrace();
  550 + $trace = '';
  551 + for( $i = count( $backtrace )-1; $i >= 0 ; $i-- )
  552 + {
  553 + if (isset($backtrace[$i]['class']))
  554 + {
  555 + $trace .= sprintf("\n%s %s %s()", $backtrace[$i]['class'], $backtrace[$i]['type'], $backtrace[$i]['function']);
  556 + }
  557 + else
  558 + {
  559 + $trace .= sprintf("\n%s()", $backtrace[$i]['function']);
  560 + }
  561 +
  562 + if (isset($backtrace[$i]['file']))
  563 + {
  564 + $trace .= sprintf(' @ %s:%d', $backtrace[$i]['file'], $backtrace[$i]['line']);
  565 + }
  566 + }
  567 + }
  568 +
546 569 if (isset($_SERVER['HTTP_HOST']))
547 570 {
548 571 // output as html
549   - echo "<br /><b>jos-$level_human</b>: " . $error->get('message') . "<br />\n";
  572 + echo "<br /><b>jos-$level_human</b>: "
  573 + . $error->get('message') . "<br />\n"
  574 + . (constant('JDEBUG') ? nl2br($trace) : '');
550 575 }
551 576 else
552 577 {
@@ -554,10 +579,18 @@ public static function handleEcho(&$error, $options)
554 579 if (defined('STDERR'))
555 580 {
556 581 fwrite(STDERR, "J$level_human: " . $error->get('message') . "\n");
  582 + if (constant('JDEBUG'))
  583 + {
  584 + frwite(STDERR, $trace);
  585 + }
557 586 }
558 587 else
559 588 {
560 589 echo "J$level_human: " . $error->get('message') . "\n";
  590 + if (constant('JDEBUG'))
  591 + {
  592 + echo $trace;
  593 + }
561 594 }
562 595 }
563 596
@@ -768,11 +801,19 @@ public static function customErrorPage(&$error)
768 801 $document->setTitle(JText::_('Error') . ': ' . $error->get('code'));
769 802 $data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => $config->get('debug')));
770 803
771   - // Do not allow cache
772   - JResponse::allowCache(false);
  804 + // Failsafe to get the error displayed.
  805 + if (empty($data))
  806 + {
  807 + self::handleEcho($error, array());
  808 + }
  809 + else
  810 + {
  811 + // Do not allow cache
  812 + JResponse::allowCache(false);
773 813
774   - JResponse::setBody($data);
775   - echo JResponse::toString();
  814 + JResponse::setBody($data);
  815 + echo JResponse::toString();
  816 + }
776 817 }
777 818 else
778 819 {

0 comments on commit 3e0bfb5

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