|
| 1 | +{use Tracy\BlueScreen} |
| 2 | +{use Tracy\Debugger} |
| 3 | +{use Tracy\Dumper} |
| 4 | +{use Tracy\Helpers} |
| 5 | +{* |
| 6 | + * BlueScreen rendered as markdown text (for AI agents and CLI). |
| 7 | + * |
| 8 | + * @var Throwable $exception |
| 9 | + * @var bool $showEnvironment |
| 10 | + * @var ?array{type: int, message: string, file: string, line: int} $lastError |
| 11 | + * @var array<string, string> $httpHeaders |
| 12 | + * @var string $source |
| 13 | + * @var BlueScreen $blueScreen |
| 14 | + *} |
| 15 | +This is an error page generated by Tracy (https://tracy.nette.org). |
| 16 | + |
| 17 | +{do $_blocks = []} |
| 18 | +{define renderSource $file, $line} |
| 19 | +{do $srcLines = @file($file)} |
| 20 | +{if $srcLines} |
| 21 | +{do $start = (int) max(0, $line - 6)} |
| 22 | +{do $end = (int) min(count($srcLines), $line + 4)} |
| 23 | + |
| 24 | +```php |
| 25 | +{foreach array_slice($srcLines, $start, $end - $start, true) as $i => $srcLine} |
| 26 | +{=sprintf('%s%4d | %s', $i + 1 === $line ? ' > ' : ' ', $i + 1, rtrim($srcLine))} |
| 27 | +{/foreach} |
| 28 | +``` |
| 29 | +{do $mapped = Debugger::mapSource($file, $line)} |
| 30 | +{if $mapped && @is_file($mapped['file'])} |
| 31 | +{do $mLine = $mapped['line']} |
| 32 | + |
| 33 | +Mapped source: {=$mapped['file'] . ($mLine ? ':' . $mLine : '')} |
| 34 | +{do $mappedLines = @file($mapped['file'])} |
| 35 | +{if $mappedLines && $mLine} |
| 36 | +{do $mStart = (int) max(0, $mLine - 6)} |
| 37 | +{do $mEnd = (int) min(count($mappedLines), $mLine + 4)} |
| 38 | + |
| 39 | +``` |
| 40 | +{foreach array_slice($mappedLines, $mStart, $mEnd - $mStart, true) as $i => $srcLine} |
| 41 | +{=sprintf('%s%4d | %s', $i + 1 === $mLine ? ' > ' : ' ', $i + 1, rtrim($srcLine))} |
| 42 | +{/foreach} |
| 43 | +``` |
| 44 | +{/if} |
| 45 | +{/if} |
| 46 | +{/if} |
| 47 | +{/define} |
| 48 | +{foreach Helpers::getExceptionChain($exception) as $i => $ex} |
| 49 | +{do $title = $ex instanceof \ErrorException ? Helpers::errorTypeToString($ex->getSeverity()) : get_debug_type($ex)} |
| 50 | +{do $code = $ex->getCode() ? ' #' . $ex->getCode() : ''} |
| 51 | +{if $i === 0} |
| 52 | +# {$title}: {$ex->getMessage()}{$code} |
| 53 | +{else} |
| 54 | + |
| 55 | +## Caused by: {$title}: {$ex->getMessage()}{$code} |
| 56 | +{/if} |
| 57 | + |
| 58 | +in {$ex->getFile()}:{$ex->getLine()} |
| 59 | +{include renderSource $ex->getFile(), $ex->getLine()} |
| 60 | +{do $base = new \Exception} |
| 61 | +{if count(get_mangled_object_vars($ex)) > count(get_mangled_object_vars($base))} |
| 62 | + |
| 63 | +## Exception Properties |
| 64 | + |
| 65 | +{=Dumper::toText($ex, [Dumper::DEPTH => $blueScreen->maxDepth, Dumper::TRUNCATE => $blueScreen->maxLength, Dumper::ITEMS => $blueScreen->maxItems, Dumper::SCRUBBER => $blueScreen->scrubber, Dumper::KEYS_TO_HIDE => $blueScreen->keysToHide])} |
| 66 | +{/if} |
| 67 | +{do $stack = BlueScreen::cleanStackTrace($ex->getTrace())} |
| 68 | +{if $stack} |
| 69 | + |
| 70 | +## Stack Trace |
| 71 | + |
| 72 | +{foreach $stack as $j => $row} |
| 73 | +{do $call = isset($row['class']) ? $row['class'] . ($row['type'] ?? '::') . $row['function'] . '()' : $row['function'] . '()'} |
| 74 | +{do $location = isset($row['file']) ? $row['file'] . ':' . ($row['line'] ?? '?') : 'inner-code'} |
| 75 | +{=$j + 1}. {$call} {$location} |
| 76 | +{if !empty($row['args'])} |
| 77 | +{try} |
| 78 | +{do $params = isset($row['class']) ? (new \ReflectionMethod($row['class'], $row['function']))->getParameters() : (new \ReflectionFunction($row['function']))->getParameters()} |
| 79 | +{rollback} |
| 80 | +{do $params = []} |
| 81 | +{/try} |
| 82 | +{foreach $row['args'] as $k => $v} |
| 83 | +{do $name = isset($params[$k]) && !$params[$k]->isVariadic() ? '$' . $params[$k]->getName() : '#' . $k} |
| 84 | +{=' ' . $name . ' = ' . Dumper::toText($v, [Dumper::DEPTH => 2, Dumper::TRUNCATE => 100])} |
| 85 | +{/foreach} |
| 86 | +{/if} |
| 87 | +{/foreach} |
| 88 | +{do $shown = 0} |
| 89 | +{foreach $stack as $row} |
| 90 | +{continueIf $shown >= 2} |
| 91 | +{if isset($row['file'], $row['line']) && @is_file($row['file'])} |
| 92 | +{include renderSource $row['file'], $row['line']} |
| 93 | +{do $shown++} |
| 94 | +{/if} |
| 95 | +{/foreach} |
| 96 | +{/if} |
| 97 | +{/foreach} |
| 98 | +{if $lastError} |
| 99 | + |
| 100 | +## Last Muted Error |
| 101 | + |
| 102 | +{=Helpers::errorTypeToString($lastError['type'])}: {$lastError['message']} |
| 103 | +in {$lastError['file']}:{=$lastError['line']} |
| 104 | +{if @is_file($lastError['file'])} |
| 105 | +{include renderSource $lastError['file'], $lastError['line']} |
| 106 | +{/if} |
| 107 | +{/if} |
| 108 | +{if !Helpers::isCli() && isset($_SERVER['REQUEST_METHOD'])} |
| 109 | + |
| 110 | +## HTTP Request |
| 111 | + |
| 112 | +{$_SERVER['REQUEST_METHOD']} {$source} |
| 113 | +{if $httpHeaders} |
| 114 | + |
| 115 | +### Headers |
| 116 | + |
| 117 | +{foreach $httpHeaders as $k => $v} |
| 118 | +- {$k}: {$v} |
| 119 | +{/foreach} |
| 120 | +{/if} |
| 121 | +{if !empty($_GET)} |
| 122 | + |
| 123 | +### $_GET |
| 124 | + |
| 125 | +{=Dumper::toText($_GET, [Dumper::DEPTH => 3, Dumper::TRUNCATE => 200])} |
| 126 | +{/if} |
| 127 | +{if !empty($_POST)} |
| 128 | + |
| 129 | +### $_POST |
| 130 | + |
| 131 | +{=Dumper::toText($_POST, [Dumper::DEPTH => 3, Dumper::TRUNCATE => 200, Dumper::SCRUBBER => $blueScreen->scrubber, Dumper::KEYS_TO_HIDE => $blueScreen->keysToHide])} |
| 132 | +{/if} |
| 133 | +{if !empty($_COOKIE)} |
| 134 | + |
| 135 | +### $_COOKIE |
| 136 | + |
| 137 | +{=Dumper::toText($_COOKIE, [Dumper::DEPTH => 3, Dumper::TRUNCATE => 200, Dumper::SCRUBBER => $blueScreen->scrubber, Dumper::KEYS_TO_HIDE => $blueScreen->keysToHide])} |
| 138 | +{/if} |
| 139 | +{/if} |
| 140 | +{if $showEnvironment} |
| 141 | + |
| 142 | +## Environment |
| 143 | + |
| 144 | +| Key | Value | |
| 145 | +|-----|-------| |
| 146 | +| PHP | {=PHP_VERSION . ' (' . (PHP_ZTS ? 'TS' : 'NTS') . ')'} | |
| 147 | +{if isset($_SERVER['REQUEST_METHOD'])} |
| 148 | +| Method | {$_SERVER['REQUEST_METHOD']} | |
| 149 | +{/if} |
| 150 | +| Source | {$source} | |
| 151 | +{if isset($_SERVER['SERVER_SOFTWARE'])} |
| 152 | +| Server | {$_SERVER['SERVER_SOFTWARE']} | |
| 153 | +{/if} |
| 154 | +| Tracy | {=Debugger::Version} | |
| 155 | +{/if} |
0 commit comments