web: Improve error page
Add some useful links, including a link to a pre-filled bug report form
This commit is contained in:
parent
e4b72b22ad
commit
5aca2d51e5
4 changed files with 63 additions and 5 deletions
|
|
@ -23,6 +23,7 @@ import os
|
|||
import sys
|
||||
import threading
|
||||
import time
|
||||
import datetime
|
||||
from collections import OrderedDict, namedtuple
|
||||
from re import search, sub
|
||||
from urllib import parse
|
||||
|
|
@ -39,6 +40,7 @@ from .query import get_query
|
|||
from .web_utils import ProjectConverter, IdentConverter, validate_version, validate_project, validate_ident
|
||||
|
||||
VERSION_CACHE_DURATION_SECONDS = 2 * 60 # 2 minutes
|
||||
ADD_ISSUE_LINK = "https://github.com/bootlin/elixir/issues/new"
|
||||
|
||||
# Error with extra information about browsed project,
|
||||
# to be used in project/version URLs
|
||||
|
|
@ -51,8 +53,28 @@ class ElixirProjectError(falcon.errors.HTTPError):
|
|||
self.extra_template_args = extra_template_args
|
||||
super().__init__(status, title=title, description=description, **kwargs)
|
||||
|
||||
# Generate a summary of error details for a bug report
|
||||
def generate_error_details(req, resp, title, details):
|
||||
return f"Request date: {datetime.datetime.now()}\n" + \
|
||||
f"Path: {req.path}\n" + \
|
||||
f"Query string: {req.query_string}\n" + \
|
||||
f"Method: {req.method}\n" + \
|
||||
f"Status code: {resp.status}\n" + \
|
||||
f"Error title: {title}\n" + \
|
||||
f"Error details: {details}\n"
|
||||
|
||||
def get_github_issue_link(details: str):
|
||||
body = "TODO: add information on how you reached the error here. Please make sure details below are correct and what you want to share.\n" + \
|
||||
"---\n" + \
|
||||
details
|
||||
|
||||
return ADD_ISSUE_LINK + "?body=" + parse.quote(body)
|
||||
|
||||
|
||||
# Generate an error page from ElixirProjectError
|
||||
def get_project_error_page(req, resp, exception: ElixirProjectError):
|
||||
report_error_details = generate_error_details(req, resp, exception.title, exception.description)
|
||||
|
||||
template_ctx = {
|
||||
'projects': get_projects(req.context.config.project_dir),
|
||||
'topbar_families': TOPBAR_FAMILIES,
|
||||
|
|
@ -60,7 +82,8 @@ def get_project_error_page(req, resp, exception: ElixirProjectError):
|
|||
'current_family': 'A',
|
||||
'source_base_url': '/',
|
||||
|
||||
'referer': req.referer,
|
||||
'referer': req.referer if req.referer != req.uri else None,
|
||||
'bug_report_link': get_github_issue_link(report_error_details),
|
||||
|
||||
'error_title': exception.title,
|
||||
}
|
||||
|
|
@ -112,7 +135,9 @@ def get_project_error_page(req, resp, exception: ElixirProjectError):
|
|||
return result
|
||||
|
||||
# Generate an error page from falcon exceptions
|
||||
def get_error_page(req, exception: ElixirProjectError):
|
||||
def get_error_page(req, resp, exception: ElixirProjectError):
|
||||
report_error_details = generate_error_details(req, resp, exception.title, exception.description)
|
||||
|
||||
template_ctx = {
|
||||
'projects': get_projects(req.context.config.project_dir),
|
||||
'topbar_families': TOPBAR_FAMILIES,
|
||||
|
|
@ -121,6 +146,7 @@ def get_error_page(req, exception: ElixirProjectError):
|
|||
'source_base_url': '/',
|
||||
|
||||
'referer': req.referer,
|
||||
'bug_report_link': ADD_ISSUE_LINK + parse.quote(report_error_details),
|
||||
|
||||
'error_title': exception.title,
|
||||
}
|
||||
|
|
@ -711,7 +737,7 @@ def error_serializer(req, resp, exception):
|
|||
if isinstance(exception, ElixirProjectError):
|
||||
resp.text = get_project_error_page(req, resp, exception)
|
||||
else:
|
||||
resp.text = get_error_page(req, exception)
|
||||
resp.text = get_error_page(req, resp, exception)
|
||||
resp.content_type = falcon.MEDIA_HTML
|
||||
|
||||
resp.append_header('Vary', 'Accept')
|
||||
|
|
|
|||
|
|
@ -102,6 +102,11 @@ h2 {
|
|||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #6d7dd2;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
/* oocss */
|
||||
|
||||
|
|
@ -648,6 +653,21 @@ h2 {
|
|||
padding: 1.5em;
|
||||
}
|
||||
|
||||
#error-details {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
#error-details-links * {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#error-details-links button {
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
/* ident */
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,19 @@
|
|||
|
||||
<div class="lxrerror">
|
||||
<h2>{{ error_title }}</h2>
|
||||
{{ error_details|default('') }}
|
||||
<div id="error-details">
|
||||
{{ error_details|default('') }}
|
||||
</div>
|
||||
<span>You might want to:</span>
|
||||
<ul>
|
||||
{% if referer is not none -%}
|
||||
<li><a class="link" href="{{ referer }}">Go back</a></li>
|
||||
{%- endif %}
|
||||
<li><a class="link" href="/">Go to home page</a></li>
|
||||
{% if bug_report_link is not none -%}
|
||||
<li><a class="link" href="{{ bug_report_link }}">Report a bug</a></li>
|
||||
{%- endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
Elixir Cross Referencer - Explore source code in your browser - Particularly useful for the Linux kernel and other low-level projects in C/C++ (bootloaders, C libraries...)
|
||||
{%- endblock %}">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1" />
|
||||
<link rel="stylesheet" href="/static/style.css?v=10">
|
||||
<link rel="stylesheet" href="/static/style.css?v=11">
|
||||
<link rel="stylesheet" href="/static/banner.css">
|
||||
<link rel="stylesheet" href="/static/autocomplete.css?v=2">
|
||||
<script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue