Fix debug screen.
This commit is contained in:
parent
b6f0c88320
commit
a7eb8e930c
35
main.py
35
main.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
"""Check prices of ferries to France."""
|
"""Check prices of ferries to France."""
|
||||||
|
|
||||||
|
import collections
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -8,7 +9,6 @@ import os.path
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import collections
|
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
@ -23,11 +23,6 @@ import ferry
|
||||||
from ferry.api import get_accommodations, get_prices
|
from ferry.api import get_accommodations, get_prices
|
||||||
from ferry.read_config import ferry_config, vehicle_from_config
|
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 = flask.Flask(__name__)
|
||||||
app.debug = True
|
app.debug = True
|
||||||
|
|
||||||
|
@ -87,24 +82,23 @@ def get_duration(depart: str, arrive: str, time_delta: int) -> str:
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(werkzeug.exceptions.InternalServerError)
|
@app.errorhandler(werkzeug.exceptions.InternalServerError)
|
||||||
def exception_handler(e: Exception) -> tuple[str, int]:
|
def exception_handler(e: werkzeug.exceptions.InternalServerError) -> tuple[str, int]:
|
||||||
"""Show error page."""
|
"""Handle exception."""
|
||||||
exec_type, exc_value, current_traceback = sys.exc_info()
|
exec_type, exc_value, current_traceback = sys.exc_info()
|
||||||
assert exc_value
|
assert exc_value
|
||||||
tb = DebugTraceback(exc_value)
|
tb = DebugTraceback(exc_value)
|
||||||
|
|
||||||
summary = tb.render_traceback_html(include_title=False)
|
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 = list(traceback.walk_tb(current_traceback))[-1][0]
|
||||||
last_frame = frames[-1]
|
|
||||||
last_frame_args = inspect.getargs(last_frame.f_code)
|
last_frame_args = inspect.getargs(last_frame.f_code)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
flask.render_template(
|
flask.render_template(
|
||||||
"show_error.html",
|
"show_error.html",
|
||||||
plaintext=tb.render_traceback_text(),
|
plaintext=tb.render_traceback_text(),
|
||||||
exception="".join(exc_lines),
|
exception=exc_lines,
|
||||||
exception_type=tb._te.exc_type.__name__,
|
exception_type=tb._te.exc_type.__name__,
|
||||||
summary=summary,
|
summary=summary,
|
||||||
last_frame=last_frame,
|
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:
|
def parse_date(d: str) -> date:
|
||||||
"""Parse a date from a string in ISO format."""
|
"""Parse a date from a string in ISO format."""
|
||||||
return datetime.strptime(d, "%Y-%m-%d").date()
|
return datetime.strptime(d, "%Y-%m-%d").date()
|
||||||
|
|
|
@ -12,19 +12,12 @@
|
||||||
<pre>{{ exception }}</pre>
|
<pre>{{ exception }}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% set body %}
|
|
||||||
URL: {{ request.url }}
|
|
||||||
|
|
||||||
{{ tb.plaintext | safe }}
|
|
||||||
{% endset %}
|
|
||||||
|
|
||||||
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
|
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
|
||||||
{{ summary | safe }}
|
{{ summary | safe }}
|
||||||
|
|
||||||
{#
|
<p>Error in function "{{ last_frame.f_code.co_name }}": {{ last_frame_args | pprint }}</p>
|
||||||
<p>Error in function "{{ last_frame.function_name }}": {{ last_frame_args | pprint }}</p>
|
<pre>{{ last_frame.f_locals | pprint }}</pre>
|
||||||
<pre>{{ last_frame.locals | pprint }}</pre>
|
|
||||||
#}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue