-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy patherror.spt
More file actions
122 lines (109 loc) · 4.18 KB
/
error.spt
File metadata and controls
122 lines (109 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os.path
import sys
from pando.http import status_strings
from pando.utils import utcnow
from liberapay.exceptions import LazyResponse
from liberapay.i18n.base import HTTP_ERRORS
python_dir = f"python{sys.version_info.major}.{sys.version_info.minor}"
project_root = website.project_root.rstrip(os.path.sep) + os.path.sep
def get_short_traceback(exception):
tb = getattr(exception, '__traceback__', None)
if tb:
r = []
for i in range(25):
frame = tb.tb_frame
filepath = frame.f_code.co_filename.split(os.path.sep)
try:
i = filepath.index(python_dir)
except Exception:
filepath = os.path.sep.join(filepath)
if filepath.startswith(project_root):
filepath = filepath.removeprefix(project_root)
else:
if filepath[i+1] == 'site-packages':
i += 1
filepath = os.path.sep.join(filepath[i+1:])
r.append(f'{filepath}:{tb.tb_lineno} ({frame.f_code.co_name})')
tb = tb.tb_next
if tb is None:
break
return '\n ' + '\n '.join(r)
else:
return ' none'
def render_cookies(request):
return '; '.join(
f"{name}=[{len(value)} bytes]" for name, value in request.cookies.items()
) or 'none'
[----------------------------------------]
sentry_ident = state.get('sentry_ident')
code = response.code
msg = _(HTTP_ERRORS[code]) if code in HTTP_ERRORS else status_strings.get(code, '')
if not msg:
website.tell_sentry(Warning(f"missing error message for HTTP code {code}"))
if isinstance(response, LazyResponse):
response.render_body(state)
err = response.text
if not err:
if code == 404:
err = _("The requested page couldn't be found.")
elif code == 500:
err = _("Looks like you've found a bug! Sorry for the inconvenience. We'll fix this error as soon as possible.")
else:
err = _("An unspecified error occured. This isn't supposed to happen. Sorry.")
debugging_info = None if sentry_ident else f"""\
URL: {website.canonical_scheme}://{request.hostname}{request.line.uri.decoded}
Method: {request.method}
Referer: {request.headers.get(b'Referer')!r}
User-Agent: {request.headers.get(b'User-Agent')!r}
Cookies: {render_cookies(request)}
IP address: {request.source} ({request.source_country})
Time: {utcnow()}
Response code: {code}
Response message: {err!r}
User: {user}
Locale: {locale}
Website version: {website.version}
Traceback:{get_short_traceback(response.__cause__ or response)}
"""
[----------------------------------------] text/html
% extends "templates/layouts/base.html"
% set title = '' if response.html_template is defined else msg
% block content
% if response.html_template is defined
% include response.html_template
% else
% if '\n' in err
<pre class="alert alert-danger">{{ err }}</pre>
% else
<div class="alert alert-danger">{{ err }}</div>
% endif
% if sentry_ident
<p>{{ _(
"The details of this error have been recorded. If you decide to "
"{link_start}contact us{link_end}, please include the following "
"error identification code in your message: {0}.",
'<code>%s</code>'|safe % sentry_ident,
link_start='<a href="/about/contact" target="_blank">'|safe,
link_end='</a>'|safe,
) }}</p>
% else
<p>{{ _(
"If you decide to {link_start}contact us{link_end} about this "
"issue, please include the following debugging information in "
"your message:",
link_start='<a href="/about/contact" target="_blank">'|safe,
link_end='</a>'|safe,
) }}</p>
<pre>{{ debugging_info }}</pre>
% endif
% endif
% endblock
[----------------------------------------] application/json via json_dump
{
"debugging_info": debugging_info,
"error_code": code,
"error_id": sentry_ident,
"error_message_long": err,
"error_message_short": msg,
"html_template": getattr(response, 'html_template', None),
}