Skip to content

Commit 59383f1

Browse files
tricoder42timgraham
authored andcommitted
Ref #23643 -- Added plain text report of exception chain.
1 parent c954931 commit 59383f1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

django/views/debug.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,15 @@ def default_urlconf(request):
889889
{% else %}
890890
{{ source_line.0 }} : {{ source_line.1 }}
891891
{% endifequal %}{% endfor %}{% endif %}
892-
Traceback:
893-
{% for frame in frames %}File "{{ frame.filename|escape }}" in {{ frame.function|escape }}
894-
{% if frame.context_line %} {{ frame.lineno }}. {{ frame.context_line|escape }}{% endif %}
895-
{% endfor %}
892+
Traceback:{% for frame in frames %}
893+
{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}{% if frame.exc_cause_explicit %}
894+
The above exception ({{ frame.exc_cause }}) was the direct cause of the following exception:
895+
{% else %}
896+
During handling of the above exception ({{ frame.exc_cause }}), another exception occurred:
897+
{% endif %}{% endif %}{% endifchanged %}
898+
File "{{ frame.filename|escape }}" in {{ frame.function|escape }}
899+
{% if frame.context_line %} {{ frame.lineno }}. {{ frame.context_line|escape }}{% endif %}{% endfor %}
900+
896901
Exception Type: {{ exception_type|escape }}{% if request %} at {{ request.path_info|escape }}{% endif %}
897902
Exception Value: {{ exception_value|force_escape }}
898903
</textarea>

tests/view_tests/tests/py3_test_debug.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ def test_reporting_of_nested_exceptions(self):
3232

3333
explicit_exc = 'The above exception ({0}) was the direct cause of the following exception:'
3434
implicit_exc = 'During handling of the above exception ({0}), another exception occurred:'
35+
3536
reporter = ExceptionReporter(request, exc_type, exc_value, tb)
3637
html = reporter.get_traceback_html()
37-
self.assertIn(explicit_exc.format("Top level"), html)
38-
self.assertIn(implicit_exc.format("Second exception"), html)
38+
# Both messages are twice on page -- one rendered as html,
39+
# one as plain text (for pastebin)
40+
self.assertEqual(2, html.count(explicit_exc.format("Top level")))
41+
self.assertEqual(2, html.count(implicit_exc.format("Second exception")))
3942

4043
text = reporter.get_traceback_text()
4144
self.assertIn(explicit_exc.format("Top level"), text)

0 commit comments

Comments
 (0)