mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #33701 -- Added fine-grained error locations to the technical 500 debug page.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9d726c7902
commit
85b52d22fd
@@ -1,4 +1,5 @@
|
||||
import functools
|
||||
import itertools
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
@@ -15,7 +16,7 @@ from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
from django.utils.version import get_docs_version
|
||||
from django.utils.version import PY311, get_docs_version
|
||||
|
||||
# Minimal Django templates engine to render the error templates
|
||||
# regardless of the project's TEMPLATES setting. Templates are
|
||||
@@ -546,6 +547,24 @@ class ExceptionReporter:
|
||||
pre_context = []
|
||||
context_line = "<source code not available>"
|
||||
post_context = []
|
||||
|
||||
colno = tb_area_colno = ""
|
||||
if PY311:
|
||||
_, _, start_column, end_column = next(
|
||||
itertools.islice(
|
||||
tb.tb_frame.f_code.co_positions(), tb.tb_lasti // 2, None
|
||||
)
|
||||
)
|
||||
if start_column and end_column:
|
||||
underline = "^" * (end_column - start_column)
|
||||
spaces = " " * (start_column + len(str(lineno + 1)) + 2)
|
||||
colno = f"\n{spaces}{underline}"
|
||||
tb_area_spaces = " " * (
|
||||
4
|
||||
+ start_column
|
||||
- (len(context_line) - len(context_line.lstrip()))
|
||||
)
|
||||
tb_area_colno = f"\n{tb_area_spaces}{underline}"
|
||||
yield {
|
||||
"exc_cause": exc_cause,
|
||||
"exc_cause_explicit": exc_cause_explicit,
|
||||
@@ -562,6 +581,8 @@ class ExceptionReporter:
|
||||
"context_line": context_line,
|
||||
"post_context": post_context,
|
||||
"pre_context_lineno": pre_context_lineno + 1,
|
||||
"colno": colno,
|
||||
"tb_area_colno": tb_area_colno,
|
||||
}
|
||||
tb = tb.tb_next
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@
|
||||
</ol>
|
||||
{% endif %}
|
||||
<ol start="{{ frame.lineno }}" class="context-line">
|
||||
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ frame.context_line }}</pre>{% if not is_email %} <span>…</span>{% endif %}</li>
|
||||
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ frame.context_line }}{{ frame.colno }}</pre>{% if not is_email %} <span>…</span>{% endif %}</li>
|
||||
</ol>
|
||||
{% if frame.post_context and not is_email %}
|
||||
<ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">
|
||||
@@ -327,7 +327,7 @@ The above exception ({{ frame.exc_cause|force_escape }}) was the direct cause of
|
||||
{% else %}
|
||||
During handling of the above exception ({{ frame.exc_cause|force_escape }}), another exception occurred:
|
||||
{% endif %}{% endif %}{% endifchanged %} {% if frame.tb %}File "{{ frame.filename }}"{% if frame.context_line %}, line {{ frame.lineno }}{% endif %}, in {{ frame.function }}
|
||||
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}{% endfor %}
|
||||
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{{ frame.tb_area_colno }}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}{% endfor %}
|
||||
|
||||
Exception Type: {{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %}
|
||||
Exception Value: {{ exception_value|force_escape }}{% if exception_notes %}{{ exception_notes }}{% endif %}
|
||||
|
||||
@@ -31,7 +31,7 @@ Traceback (most recent call last):
|
||||
{% for frame in frames %}{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}
|
||||
{% if frame.exc_cause_explicit %}The above exception ({{ frame.exc_cause }}) was the direct cause of the following exception:{% else %}During handling of the above exception ({{ frame.exc_cause }}), another exception occurred:{% endif %}
|
||||
{% endif %}{% endifchanged %} {% if frame.tb %}File "{{ frame.filename }}"{% if frame.context_line %}, line {{ frame.lineno }}{% endif %}, in {{ frame.function }}
|
||||
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}
|
||||
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{{ frame.tb_area_colno }}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}
|
||||
{% endfor %}
|
||||
{% if exception_type %}Exception Type: {{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %}
|
||||
{% if exception_value %}Exception Value: {{ exception_value }}{% endif %}{% if exception_notes %}{{ exception_notes }}{% endif %}{% endif %}{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user