Fix debug screen.

This commit is contained in:
Edward Betts 2023-09-11 11:38:45 +05:30
parent b6f0c88320
commit a7eb8e930c
2 changed files with 9 additions and 39 deletions

35
main.py
View file

@ -1,6 +1,7 @@
#!/usr/bin/python3
"""Check prices of ferries to France."""
import collections
import inspect
import json
import os
@ -8,7 +9,6 @@ import os.path
import re
import sys
import traceback
import collections
from datetime import date, datetime, timedelta
from typing import Any
@ -23,11 +23,6 @@ import ferry
from ferry.api import get_accommodations, get_prices
from ferry.read_config import ferry_config, vehicle_from_config
# import werkzeug.exceptions
# from werkzeug.debug.tbtools import DebugTraceback
# from werkzeug.debug.tbtools import get_current_traceback
app = flask.Flask(__name__)
app.debug = True
@ -87,24 +82,23 @@ def get_duration(depart: str, arrive: str, time_delta: int) -> str:
@app.errorhandler(werkzeug.exceptions.InternalServerError)
def exception_handler(e: Exception) -> tuple[str, int]:
"""Show error page."""
def exception_handler(e: werkzeug.exceptions.InternalServerError) -> tuple[str, int]:
"""Handle exception."""
exec_type, exc_value, current_traceback = sys.exc_info()
assert exc_value
tb = DebugTraceback(exc_value)
summary = tb.render_traceback_html(include_title=False)
exc_lines = list(tb._te.format_exception_only())
exc_lines = "".join(tb._te.format_exception_only())
frames = [f for f, lineno in traceback.walk_tb(current_traceback)]
last_frame = frames[-1]
last_frame = list(traceback.walk_tb(current_traceback))[-1][0]
last_frame_args = inspect.getargs(last_frame.f_code)
return (
flask.render_template(
"show_error.html",
plaintext=tb.render_traceback_text(),
exception="".join(exc_lines),
exception=exc_lines,
exception_type=tb._te.exc_type.__name__,
summary=summary,
last_frame=last_frame,
@ -114,23 +108,6 @@ def exception_handler(e: Exception) -> tuple[str, int]:
)
# @app.errorhandler(werkzeug.exceptions.InternalServerError)
# def exception_handler(e):
# # tb = get_current_traceback()
# tb = DebugTraceback()
# last_frame = next(frame for frame in reversed(tb.frames) if not frame.is_library)
# last_frame_args = inspect.getargs(last_frame.code)
# return (
# flask.render_template(
# "show_error.html",
# tb=tb,
# last_frame=last_frame,
# last_frame_args=last_frame_args,
# ),
# 500,
# )
def parse_date(d: str) -> date:
"""Parse a date from a string in ISO format."""
return datetime.strptime(d, "%Y-%m-%d").date()

View file

@ -12,19 +12,12 @@
<pre>{{ exception }}</pre>
</div>
{% set body %}
URL: {{ request.url }}
{{ tb.plaintext | safe }}
{% endset %}
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
{{ summary | safe }}
{#
<p>Error in function "{{ last_frame.function_name }}": {{ last_frame_args | pprint }}</p>
<pre>{{ last_frame.locals | pprint }}</pre>
#}
<p>Error in function "{{ last_frame.f_code.co_name }}": {{ last_frame_args | pprint }}</p>
<pre>{{ last_frame.f_locals | pprint }}</pre>
</div>
{% endblock %}