Permalink
Browse files

Improving the exception stack traces.

Adding Debugger::getType()
  • Loading branch information...
1 parent f5ae962 commit 183ffb29d7f3cbf789c3241b7dc88708d1b530a0 @markstory markstory committed Oct 9, 2011
Showing with 103 additions and 4 deletions.
  1. +16 −0 app/webroot/css/cake.generic.css
  2. +35 −0 lib/Cake/Utility/Debugger.php
  3. +52 −4 lib/Cake/View/Elements/exception_stack_trace.ctp
@@ -646,6 +646,22 @@ pre {
overflow: auto;
text-shadow: none;
}
+.cake-stack-trace li {
+ padding: 10px 5px 0px;
+ margin: 0 0 4px 0;
+ font-family: monospace;
+ border: 1px solid #bbb;
+ -moz-border-radius: 4px;
+ -wekbkit-border-radius: 4px;
+ border-radius: 4px;
+ background: #dcdcdc;
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#dcdcdc));
+ background-image: -webkit-linear-gradient(top, #fefefe, #dcdcdc);
+ background-image: -moz-linear-gradient(top, #fefefe, #dcdcdc);
+ background-image: -ms-linear-gradient(top, #fefefe, #dcdcdc);
+ background-image: -o-linear-gradient(top, #fefefe, #dcdcdc);
+ background-image: linear-gradient(top, #fefefe, #dcdcdc);
+}
/* excerpt */
.cake-code-dump pre,
.cake-code-dump pre code {
@@ -704,6 +704,41 @@ public function outputError($data) {
}
/**
+ * Get the type of the given variable. Will return the classname
+ * for objects.
+ *
+ * @param mixed $var The variable to get the type of
+ * @return string The type of variable.
+ */
+ public static function getType($var) {
+ if (is_object($var)) {
+ return get_class($var);
+ }
+ if (is_null($var)) {
+ return 'null';
+ }
+ if (is_string($var)) {
+ return 'string';
+ }
+ if (is_array($var)) {
+ return 'array';
+ }
+ if (is_int($var)) {
+ return 'integer';
+ }
+ if (is_bool($var)) {
+ return 'boolean';
+ }
+ if (is_float($var)) {
+ return 'float';
+ }
+ if (is_resource($var)) {
+ return 'resource';
+ }
+ return 'unknown';
+ }
+
+/**
* Verifies that the application's salt and cipher seed value has been changed from the default value.
*
* @return void
@@ -16,8 +16,56 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('Debugger', 'Utility');
?>
-<h4>Stack Trace</h4>
-<pre>
-<?php echo $error->getTraceAsString(); ?>
-</pre>
+<h3>Stack Trace</h3>
+<ul class="cake-stack-trace">
+<?php foreach ($error->getTrace() as $i => $stack): ?>
+ <li><?php
+ $excerpt = $arguments = '';
+ $params = array();
+
+ if (isset($stack['file']) && isset($stack['line'])):
+ printf(
+ '<a href="#" onclick="traceToggle(event, \'file-excerpt-%s\')">%s line %s</a>',
+ $i,
+ $stack['file'],
+ $stack['line']
+ );
+ $excerpt = sprintf('<div id="file-excerpt-%s" class="cake-code-dump" style="display:none;"><pre>', $i);
+ $excerpt .= implode("\n", Debugger::excerpt($stack['file'], $stack['line'] - 1, 2));
+ $excerpt .= '</pre></div> ';
+ endif;
+ echo ' &rarr; ';
+ if ($stack['function']):
+ $args = array();
+ foreach ($stack['args'] as $arg):
+ $args[] = Debugger::getType($arg);
+ $params[] = Debugger::exportVar($arg, 2);
+ endforeach;
+
+ printf(
+ '<a href="#" onclick="traceToggle(event, \'trace-args-%s\')">%s%s%s(%s)</a> ',
+ $i,
+ $stack['class'],
+ $stack['type'],
+ $stack['function'],
+ implode(', ', $args)
+ );
+ $arguments = sprintf('<div id="trace-args-%s" class="cake-code-dump" style="display: none;"><pre>', $i);
+ $arguments .= implode("\n", $params);
+ $arguments .= '</pre></div>';
+ endif;
+ echo $excerpt;
+ echo $arguments;
+ ?></li>
+<?php endforeach; ?>
+</ul>
+<script type="text/javascript">
+function traceToggle(event, id) {
+ var el = document.getElementById(id);
+ el.style.display = (el.style.display == 'block') ? 'none' : 'block';
+ event.preventDefault();
+ return false;
+}
+</script>

0 comments on commit 183ffb2

Please sign in to comment.