From d7926aaaad9ff340e9a297857b4b5ab8d8dc70bd Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 24 Dec 2007 23:47:46 +0000 Subject: [PATCH] adding context and trace to other debugger output formats. adds E_USER_ERROR to fatal git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6242 3807eeeb-6ff5-0310-8944-8be069107fe0 --- app/webroot/css/cake.generic.css | 2 +- .../skel/webroot/css/cake.generic.css | 2 +- cake/libs/debugger.php | 88 +++++++++++-------- cake/tests/cases/libs/debugger.test.php | 64 +++++++++++++- 4 files changed, 114 insertions(+), 42 deletions(-) diff --git a/app/webroot/css/cake.generic.css b/app/webroot/css/cake.generic.css index 76eafb5f5..7b34404ff 100644 --- a/app/webroot/css/cake.generic.css +++ b/app/webroot/css/cake.generic.css @@ -407,7 +407,7 @@ div.cake-stack-trace pre, div.cake-code-dump pre { div.cake-code-dump pre, div.cake-code-dump pre code { clear: both; font-size: 12px; - line-height: 7px; + line-height: 15px; margin: 4px 2px; padding: 4px; overflow: auto; diff --git a/cake/console/libs/templates/skel/webroot/css/cake.generic.css b/cake/console/libs/templates/skel/webroot/css/cake.generic.css index f687b43fc..a641d1c67 100644 --- a/cake/console/libs/templates/skel/webroot/css/cake.generic.css +++ b/cake/console/libs/templates/skel/webroot/css/cake.generic.css @@ -407,7 +407,7 @@ div.cake-stack-trace pre, div.cake-code-dump pre { div.cake-code-dump pre, div.cake-code-dump pre code { clear: both; font-size: 12px; - line-height: 7px; + line-height: 15px; margin: 4px 2px; padding: 4px; overflow: auto; diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index 00b16840c..5c7f3533e 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -144,6 +144,7 @@ class Debugger extends Object { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: + case E_USER_ERROR: $error = 'Fatal Error'; $level = LOG_ERROR; break; @@ -172,7 +173,7 @@ class Debugger extends Object { } } - echo $_this->__output($level, $error, $code, $description, $file, $line, $context); + echo $_this->__output($level, $error, $code, $helpCode, $description, $file, $line, $context); if (Configure::read('log')) { CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]"); @@ -297,10 +298,11 @@ class Debugger extends Object { if (!isset($data[$i])) { continue; } + $string = str_replace(array("\r\n", "\n"), "", highlight_string($data[$i], true)); if ($i == $line) { - $lines[] = '' . highlight_string($data[$i], true) . ''; + $lines[] = '' . $string . ''; } else { - $lines[] = highlight_string($data[$i], true); + $lines[] = $string; } } return $lines; @@ -323,21 +325,26 @@ class Debugger extends Object { return $var; break; case 'string': - return '"' . $var . '"'; + return '"' . h($var) . '"'; + return $echo; break; case 'object': - return $_this->__object($var); + return get_class($var) . "\n" . $_this->__object($var); case 'array': - $out = 'array('; + $out = "array("; $vars = array(); foreach ($var as $key => $val) { if (is_numeric($key)) { - $vars[] = $_this->exportVar($val, $recursion - 1); + $vars[] = "\n\t" . $_this->exportVar($val, $recursion - 1); } else { - $vars[] = $_this->exportVar($key) . ' => ' . $_this->exportVar($val, $recursion - 1); + $vars[] = "\n\t" .$_this->exportVar($key) . ' => ' . $_this->exportVar($val, $recursion - 1); } } - return $out . join(",", $vars) . ')'; + $n = null; + if (count($vars) > 0) { + $n = "\n"; + } + return $out . join(",", $vars) . "{$n})"; break; case 'resource': return strtolower(gettype($var)); @@ -376,7 +383,6 @@ class Debugger extends Object { $value = ife(is_object($value), "*RECURSION* -> " . get_class($value), "*RECURSION*"); } } - if(in_array(gettype($value), array('boolean', 'integer', 'double', 'string', 'array', 'resource', 'object', 'null'))) { $out[] = "$className::$$key = " . Debugger::exportVar($value); } else { @@ -419,60 +425,70 @@ class Debugger extends Object { * @param string $var Object to convert * @access private */ - function __output($level, $error, $code, $description, $file, $line, $context) { + function __output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) { $_this = Debugger::getInstance(); + $files = $_this->trace(array('start' => 2, 'format' => 'points')); + $listing = $_this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1); + $trace = $_this->trace(array('start' => 2)); + $context = array(); + + foreach ((array)$kontext as $var => $value) { + $context[] = "\${$var}\t=\t" . $_this->exportVar($value, 1); + } + switch ($_this->__outputFormat) { default: case 'js': $link = "document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")"; $out = "{$error} ({$code}): {$description} [{$file}, line {$line}]"; - if (Configure::read() > 0) { debug($out, false, false); e(''); } break; case 'html': echo "
{$error} ({$code}) : {$description} [{$file}, line {$line}]
"; + if (!empty($context)) { + echo "Context:\n" .implode("\n", $context) . "\n"; + } + echo "
Context 

" . implode("\n", $context) . "

"; + echo "
Trace 

" . $trace. "

"; break; case 'text': case 'txt': echo "{$error}: {$code} :: {$description} on line {$line} of {$file}\n"; + if (!empty($context)) { + echo "Context:\n" .implode("\n", $context) . "\n"; + } + echo "Trace:\n" . $trace; break; case 'log': - $_this->log(compact('error', 'code', 'description', 'line', 'file')); + $_this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace')); break; case false: - $this->__data[] = compact('error', 'code', 'description', 'line', 'file'); + $this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'); break; } diff --git a/cake/tests/cases/libs/debugger.test.php b/cake/tests/cases/libs/debugger.test.php index b66329d7b..cdd028356 100644 --- a/cake/tests/cases/libs/debugger.test.php +++ b/cake/tests/cases/libs/debugger.test.php @@ -43,14 +43,70 @@ class DebuggerTest extends UnitTestCase { $this->assertEqual($result, ''); $out .= ''; $result = Debugger::output(true); - $expected = array(array('error' => 'Notice', 'code' => '8', 'description' => 'Undefined variable: out', 'line' => '44', 'file' => 'CORE/cake/tests/cases/libs/debugger.test.php')); + $expected = array(array( + 'error' => 'Notice', 'code' => '8', 'description' => 'Undefined variable: out', 'line' => '44', 'file' => 'CORE/cake/tests/cases/libs/debugger.test.php', + 'context' => array("\$result\t=\tnull"), + 'trace' => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44 +SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42 +SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591 +TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93 +[main] - CORE/app/webroot/test.php, line 240" + ) + ); + $result = str_replace(array("\t", "\r\n", "\n"), "", $result); + $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected); $this->assertEqual($result, $expected); - ob_start(); Debugger::output('txt'); $other .= ''; $result = ob_get_clean(); - $expected = "Notice: 8 :: Undefined variable: other on line 51 of CORE/cake/tests/cases/libs/debugger.test.php\n"; + $expected = "Notice: 8 :: Undefined variable: other on line 67 of CORE/cake/tests/cases/libs/debugger.test.php\n"; + $expected .= 'Context: +$result = array(array("error" => "Notice","code" => 8,"description" => "Undefined variable: out","line" => 44,"file" => "CORE/cake/tests/cases/libs/debugger.test.php","context" => array("$result = null"),"trace" => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44 +SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42 +SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591 +TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93 +[main] - CORE/app/webroot/test.php, line 240")) +$out = "" +$expected = array(array("error" => "Notice","code" => "8","description" => "Undefined variable: out","line" => "44","file" => "CORE/cake/tests/cases/libs/debugger.test.php","context" => array("$result = null"),"trace" => "DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 44 +SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42 +SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591 +TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93 +[main] - CORE/app/webroot/test.php, line 240")) +'; + $expected .= 'Trace: +DebuggerTest::testOutput() - CORE/cake/tests/cases/libs/debugger.test.php, line 67 +SimpleInvoker::invoke() - CORE/vendors/simpletest/invoker.php, line 68 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleErrorTrappingInvoker::invoke() - CORE/vendors/simpletest/errors.php, line 48 +SimpleInvokerDecorator::invoke() - CORE/vendors/simpletest/invoker.php, line 126 +SimpleExceptionTrappingInvoker::invoke() - CORE/vendors/simpletest/exceptions.php, line 42 +SimpleTestCase::run() - CORE/vendors/simpletest/test_case.php, line 135 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 588 +TestSuite::run() - CORE/vendors/simpletest/test_case.php, line 591 +TestManager::runTestCase() - CORE/cake/tests/lib/test_manager.php, line 93 +[main] - CORE/app/webroot/test.php, line 240'; + + $result = str_replace(array("\t", "\r\n", "\n"), "", $result); + $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected); $this->assertEqual($result, $expected); set_error_handler('simpleTestErrorHandler'); @@ -63,7 +119,7 @@ class DebuggerTest extends UnitTestCase { $Controller->helpers = array('Html', 'Form'); $View = new View($Controller); $result = Debugger::exportVar($View); - $expected = 'View::$base = "[empty string]" + $expected = 'ViewView::$base = "[empty string]" View::$here = "[empty string]" View::$plugin = "[empty string]" View::$name = "[empty string]"