Skip to content

Commit dad40a6

Browse files
committed
Feature: display both filename and Sentry error ID
Show both errors if available.
1 parent 1be7a85 commit dad40a6

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

openlibrary/i18n/messages.pot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,13 @@ msgstr ""
19131913
msgid "We're sorry, a problem occurred while responding to your request:"
19141914
msgstr ""
19151915

1916+
#: internalerror.html
1917+
#, python-format
1918+
msgid ""
1919+
"The reference code %s and Sentry error ID %s have been created to track "
1920+
"this error and we will investigate as we're able."
1921+
msgstr ""
1922+
19161923
#: internalerror.html
19171924
#, python-format
19181925
msgid ""

openlibrary/plugins/openlibrary/code.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def save_error():
11471147

11481148

11491149
def internalerror():
1150-
name = save_error()
1150+
name_webpy_error = save_error()
11511151

11521152
import sys
11531153

@@ -1161,16 +1161,20 @@ def internalerror():
11611161
# TODO: move this to plugins\openlibrary\sentry.py
11621162
from openlibrary.plugins.openlibrary.sentry import sentry
11631163

1164-
event_id: str | None = None
1164+
sentry_event_id: str | None = None
11651165
if sentry.enabled:
1166-
event_id = sentry.capture_exception_webpy()
1166+
sentry_event_id = sentry.capture_exception_webpy()
11671167

11681168
if features.is_enabled('debug'):
11691169
raise web.debugerror()
11701170
else:
1171-
name = event_id if event_id else name
11721171
msg = render.site(
1173-
render.internalerror(name, etype=exception_type, evalue=exception_value)
1172+
render.internalerror(
1173+
name_webpy_error,
1174+
sentry_event_id,
1175+
etype=exception_type,
1176+
evalue=exception_value,
1177+
)
11741178
)
11751179
raise web.internalerror(msg)
11761180

openlibrary/templates/internalerror.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$def with (name, etype=None, evalue=None)
1+
$def with (name_webpy_error, sentry_event_id=None, etype=None, evalue=None)
22

33
$var title: $_("Internal Error")
44

@@ -12,6 +12,9 @@ <h1>$_("A Problem Occurred")</h1>
1212
$etype
1313
$evalue
1414
</code>
15-
<p>$:_("The reference code %s has been created to track this error and we will investigate as we're able.", name)</p>
15+
$if sentry_event_id:
16+
<p>$:_("The reference code %s and Sentry error ID %s have been created to track this error and we will investigate as we're able.", name_webpy_error, sentry_event_id)</p>
17+
$else:
18+
<p>$:_("The reference code %s has been created to track this error and we will investigate as we're able.", name_webpy_error)</p>
1619
<p>$:_('Return to the <a class="go-back-link" href="javascript:;">previous page</a>?')</p>
17-
</div>
20+
</div>

openlibrary/utils/sentry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def capture_exception_webpy(self) -> str | None:
9191
trace_id = transaction.trace_id if transaction else None
9292
return trace_id
9393

94-
9594
def capture_exception(self, ex, extras: dict | None = None):
9695
with sentry_sdk.new_scope() as scope:
9796
if extras:

0 commit comments

Comments
 (0)