$def with (exception, message, traceback)
$def head():
<style>
/*.frame > div > *, div[class|=envblock] {
float: left;
width: 45em; }*/
/*
.frame > div {
clear: left;
display: table; }
.frame table {
float: left; }
*/
.frame table td.code {
padding: 0; }
article dl {
// background-color: #073642;
display: table;
font-size: .8em;
margin: 0;
overflow: auto;
overflow-y: hidden;
width: 37em; }
article dl dt {
clear: left;
display: block;
float: left;
font-weight: bold;
width: 20%; }
article dl dd {
display: block;
float: left;
margin: 0;
width: 80%; }
article dl dd pre {
font-size: 1em;
line-height: 1.6;
margin: 0; }
/*.envblock-user > *, .envblock-request > * {
clear: left;
margin-right: 1.5em; }
.envblock-host > *, .envblock-response > * {
margin-left: 1.5em; }*/
/* .focus {
display: table;
width: 100%; } */
/* .dark .focus {
background-color: #073642; }
.light .focus {
background-color: #eee8d5; } */
article dl {
width: 100%; }
article dd pre {
width: 100%; }
</style>
<link rel=stylesheet href=$tx.origin/static/solarized.css media=screen>
<style>
div.highlight {
font-size: .75em; }
</style>
$var head = head
$var title: Something went wrong
$var subtitle: $exception.__name__: $message
$# $ query = {"q": "python " + exception.__name__ + ": " + str(message) + " !"}
$# <p>Try a <a href="https://duckduckgo.com/?$urlencode(query)">web search</a>
$# for resources related to the exception raised.</p>
$ python_docs = "https://docs.python.org/3/library"
$def render_dictionary(obj_type, obj):
<dl class="$(obj_type)-objects">
$for key, value in sorted(obj.items()):
<dt>$key</dt>
<dd>
$if isinstance(value, dict):
$:render_dictionary("dictionary", value)
$elif isinstance(value, str):
<pre>$value</pre>
$elif isinstance(value, Path):
<small><code><a
href=$python_docs/pathlib.html#pathlib.Path>path</a></code></small>
<code>$value</code>
$elif __web__ := getattr(value, "__web__", None):
<small><code><a
href=#>route</a></code></small>
<code>$(__web__[2].name).$(value.handler.__name__)<br>/$__web__[0]</code>
$else:
<pre>$pformat(value, width=80)</pre>
$# $elif isinstance(value, list):
$# <ol>
$# $for item in value:
$# <li>$item</li>
$# </ol>
</dd>
</dl>
$ frames = list(reversed(inspect.getinnerframes(traceback)))
<div>
<p><big><strong style=color:#dc322f>$exception.__name__: $message</strong></big></p>
<div id=traceback>
$# XXX <ol>
$# XXX $for n, (frame, filename, lineno, function, context, index) in enumerate(frames, 1):
$# XXX <li>
$# XXX <small><a href=#frame-$n>$filename</a></small>
$# XXX $:highlight(context[index], ".py")
$# XXX </li>
$# XXX </ol>
$for n, (frame, filename, lineno, function, context, index) in enumerate(frames, 1):
$ system_lib = filename.startswith("/usr")
<div class=frame id=frame-$n\
$if system_lib:
style=opacity:50%
>
<details \
$if n < len(frames) and not system_lib:
open
>
<summary><big><strong>$filename.removeprefix(str(getattr(tx.host, "working_dir", "")))</strong></big></summary>
$ code, starting_line = getsourcelines(frame.f_code)
$:highlight("".join(code), ".py", starting_line=starting_line, focus=lineno)
$:render_dictionary("traceback", frame.f_locals)
</details>
</div>
</div>
<hr>
<div id=environment>
<details>
<summary>Environment</summary>
<div class=envblock-user>
<h3>User</h3>
$:render_dictionary("environment-user", tx.user.__dict__)
</div>
<div class=envblock-host>
<h3>Host</h3>
$:render_dictionary("environment-host", tx.host.__dict__)
</div>
<div class=envblock-request>
<h3>Request</h3>
<p>$tx.request.method /$str(tx.request.uri.path)</p>
$:render_dictionary("environment-request", tx.request.headers.__dict__)
$ body_items = tx.request.body.items()
$if body_items:
<pre>$str(body_items)</pre>
</div>
<div class=envblock-response>
<h3>Response</h3>
<p>$str(tx.response.status)</p>
$:render_dictionary("environment-response", tx.response.headers.__dict__)
<pre>$str(tx.response.body)</pre>
</div>
</details>
</div>
</div>