Skip to content

Commit

Permalink
Start getting stack frames to look nicer.
Browse files Browse the repository at this point in the history
Add better toggles so frames can be expanded, and then the arguments can
be expanded if desired.
  • Loading branch information
markstory committed Nov 26, 2014
1 parent 66f532a commit 0714a27
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 58 deletions.
96 changes: 60 additions & 36 deletions src/Template/Element/exception_stack_trace.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,79 @@
*/
use Cake\Error\Debugger;
?>
<h3>Stack Trace</h3>
<ul class="cake-stack-trace">
<?php foreach ($error->getTrace() as $i => $stack): ?>
<li><?php
$excerpt = $arguments = '';
$params = array();
<div class="exception-stack-trace columns large-2 large-pull-10">
<h3>Stack Trace</h3>
<ul>
<?php foreach ($error->getTrace() as $i => $stack): ?>
<li class="cake-stack-frame"><?php
$excerpt = $arguments = '';
$params = array();

if (isset($stack['file']) && isset($stack['line'])):
printf(
'<a href="#" onclick="cakeExpand(event, \'stack-frame-%s\')">%s line %s</a>',
$i,
Debugger::trimPath($stack['file']),
$stack['line']
);
else:
echo '<a href="#">[internal function]</a>';
endif;
?></li>
<?php endforeach; ?>
</ul>
</div>

<div class="columns large-12">
<?php
foreach ($error->getTrace() as $i => $stack):
$excerpt = $params = [];

if (isset($stack['file']) && isset($stack['line'])):
printf(
'<a href="#" onclick="traceToggle(event, \'file-excerpt-%s\')">%s line %s</a>',
$i,
Debugger::trimPath($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> ';
// TODO add line numbers
$excerpt = Debugger::excerpt($stack['file'], $stack['line'] - 1, 2);
endif;

if (isset($stack['file'])):
$file = $stack['file'];
else:
echo '<a href="#">[internal function]</a>';
$file = '[internal function]';
endif;
echo ' &rarr; ';

if ($stack['function']):
$args = array();
if (!empty($stack['args'])):
foreach ((array)$stack['args'] as $arg):
$args[] = Debugger::getType($arg);
$params[] = Debugger::exportVar($arg, 4);
endforeach;
else:
$params[] = 'No arguments';
endif;

$called = isset($stack['class']) ? $stack['class'] . $stack['type'] . $stack['function'] : $stack['function'];

printf(
'<a href="#" onclick="traceToggle(event, \'trace-args-%s\')">%s(%s)</a> ',
$i,
$called,
h(implode(', ', $args))
);
$arguments = sprintf('<div id="trace-args-%s" class="cake-code-dump" style="display: none;"><pre>', $i);
$arguments .= h(implode("\n", $params));
$arguments .= '</pre></div>';
endif;
echo $excerpt;
echo $arguments;
?></li>
?>
<div id="stack-frame-<?= $i ?>" style="display:none;" class="cake-stack-details">
<span class="stack-frame-file"><?= h($file) ?></span>
<a href="#" onclick="cakeToggle(event, 'stack-args-<?= $i ?>')">show arguments</a>
<div class="cake-code-dump">
<pre><?= implode("\n", $excerpt) ?></pre>
</div>
<div class="cake-code-dump" id="stack-args-<?= $i ?>" style="display: none;">
<pre><?= implode("\n", $params) ?></pre>
</div>
</div>
<?php endforeach; ?>
</ul>
</div>

<script type="text/javascript">
function traceToggle(event, id) {
function cakeExpand(event, id) {
var el = document.getElementById(id);

var others = document.getElementsByClassName('cake-stack-details');
for (var i = 0, len = others.length; i < len; i++) {
others[i].style.display = 'none';
}
return cakeToggle(event, id);
}
function cakeToggle(event, id) {
var el = document.getElementById(id);
el.style.display = (el.style.display === 'block') ? 'none' : 'block';
event.preventDefault();
Expand Down
46 changes: 24 additions & 22 deletions src/Template/Error/missing_action.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,33 @@ if (empty($plugin)) {
$path = Plugin::classPath($plugin) . 'Controller' . DS . $prefix . h($controller) . '.php';
}
?>
<h2><?= sprintf('Missing Method in %s', h($controller)); ?></h2> <p class="error">
<strong>Error: </strong>
<?= sprintf('The action <em>%s</em> is not defined in controller <em>%s</em>', h($action), h($controller)); ?>
</p>
<p class="error">
<strong>Error: </strong>
<?= sprintf('Create <em>%s::%s()</em> in file: %s.', h($controller), h($action), $path); ?>
</p>
<pre>
&lt;?php
namespace <?= h($namespace); ?>\Controller<?= h($prefixNs); ?>;
<div class="columns large-10 large-push-2">
<h2><?= sprintf('Missing Method in %s', h($controller)); ?></h2> <p class="error">
<strong>Error: </strong>
<?= sprintf('The action <em>%s</em> is not defined in controller <em>%s</em>', h($action), h($controller)); ?>
</p>
<p class="error">
<strong>Error: </strong>
<?= sprintf('Create <em>%s::%s()</em> in file: %s.', h($controller), h($action), $path); ?>
</p>
<pre>
&lt;?php
namespace <?= h($namespace); ?>\Controller<?= h($prefixNs); ?>;

use <?= h($namespace); ?>\Controller\AppController;
use <?= h($namespace); ?>\Controller\AppController;

class <?= h($controller); ?> extends AppController {
class <?= h($controller); ?> extends AppController {

<strong>
public function <?= h($action); ?>() {
<strong>
public function <?= h($action); ?>() {

}
</strong>
}
</strong>
}
</pre>
<p class="notice">
<strong>Notice: </strong>
<?= sprintf('If you want to customize this error message, create %s', APP_DIR . DS . 'Template' . DS . 'Error' . DS . 'missing_action.ctp'); ?>
</p>
</pre>
<p class="notice">
<strong>Notice: </strong>
<?= sprintf('If you want to customize this error message, create %s', APP_DIR . DS . 'Template' . DS . 'Error' . DS . 'missing_action.ctp'); ?>
</p>
</div>
<?= $this->element('exception_stack_trace'); ?>

0 comments on commit 0714a27

Please sign in to comment.