mirror of https://github.com/encode/starlette.git
Merge pull request #572 from encode/tweak-exception-debug-html
Tweak exception debug HTML
This commit is contained in:
commit
8a2ae41e79
|
@ -52,6 +52,11 @@ p {
|
||||||
.collapsed {
|
.collapsed {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.source-code {
|
||||||
|
font-family: courier;
|
||||||
|
font-size: small;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
JS = """
|
JS = """
|
||||||
|
@ -96,9 +101,9 @@ FRAME_TEMPLATE = """
|
||||||
<p class="frame-filename"><span class="debug-filename frame-line">File {frame_filename}</span>,
|
<p class="frame-filename"><span class="debug-filename frame-line">File {frame_filename}</span>,
|
||||||
line <i>{frame_lineno}</i>,
|
line <i>{frame_lineno}</i>,
|
||||||
in <b>{frame_name}</b>
|
in <b>{frame_name}</b>
|
||||||
<span class="collapse-btn" data-frame-id="{frame_filename}-{frame_lineno}" onclick="collapse(this)">‒</span>
|
<span class="collapse-btn" data-frame-id="{frame_filename}-{frame_lineno}" onclick="collapse(this)">{collapse_button}</span>
|
||||||
</p>
|
</p>
|
||||||
<div id="{frame_filename}-{frame_lineno}">{code_context}</div>
|
<div id="{frame_filename}-{frame_lineno}" class="source-code {collapsed}">{code_context}</div>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -183,7 +188,9 @@ class ServerErrorMiddleware:
|
||||||
return LINE.format(**values)
|
return LINE.format(**values)
|
||||||
return CENTER_LINE.format(**values)
|
return CENTER_LINE.format(**values)
|
||||||
|
|
||||||
def generate_frame_html(self, frame: inspect.FrameInfo, center_lineno: int) -> str:
|
def generate_frame_html(
|
||||||
|
self, frame: inspect.FrameInfo, center_lineno: int, is_collapsed: bool
|
||||||
|
) -> str:
|
||||||
code_context = "".join(
|
code_context = "".join(
|
||||||
self.format_line(context_position, line, frame.lineno, center_lineno)
|
self.format_line(context_position, line, frame.lineno, center_lineno)
|
||||||
for context_position, line in enumerate(frame.code_context)
|
for context_position, line in enumerate(frame.code_context)
|
||||||
|
@ -194,6 +201,8 @@ class ServerErrorMiddleware:
|
||||||
"frame_lineno": frame.lineno,
|
"frame_lineno": frame.lineno,
|
||||||
"frame_name": frame.function,
|
"frame_name": frame.function,
|
||||||
"code_context": code_context,
|
"code_context": code_context,
|
||||||
|
"collapsed": "collapsed" if is_collapsed else "",
|
||||||
|
"collapse_button": "+" if is_collapsed else "‒",
|
||||||
}
|
}
|
||||||
return FRAME_TEMPLATE.format(**values)
|
return FRAME_TEMPLATE.format(**values)
|
||||||
|
|
||||||
|
@ -206,9 +215,12 @@ class ServerErrorMiddleware:
|
||||||
)
|
)
|
||||||
|
|
||||||
center_lineno = int((limit - 1) / 2)
|
center_lineno = int((limit - 1) / 2)
|
||||||
exc_html = "".join(
|
exc_html = ""
|
||||||
self.generate_frame_html(frame, center_lineno) for frame in reversed(frames)
|
is_collapsed = False
|
||||||
)
|
for frame in reversed(frames):
|
||||||
|
exc_html += self.generate_frame_html(frame, center_lineno, is_collapsed)
|
||||||
|
is_collapsed = True
|
||||||
|
|
||||||
error = f"{traceback_obj.exc_type.__name__}: {traceback_obj}"
|
error = f"{traceback_obj.exc_type.__name__}: {traceback_obj}"
|
||||||
|
|
||||||
return TEMPLATE.format(styles=STYLES, js=JS, error=error, exc_html=exc_html)
|
return TEMPLATE.format(styles=STYLES, js=JS, error=error, exc_html=exc_html)
|
||||||
|
|
Loading…
Reference in New Issue