1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #31672 -- Made technical 500 debug page include exceptions without tracebacks.

This commit is contained in:
Hasan Ramezani
2020-11-03 22:16:05 +01:00
committed by Mariusz Felisiak
parent a43e2f66d7
commit 4cd77f97a2
4 changed files with 65 additions and 9 deletions

View File

@@ -494,7 +494,7 @@ class ExceptionReporterTests(SimpleTestCase):
reporter = ExceptionReporter(None, exc_type, exc_value, tb)
frames = reporter.get_traceback_frames()
self.assertEqual(len(frames), 1)
self.assertEqual(len(frames), 2)
html = reporter.get_traceback_html()
self.assertInHTML('<h1>RuntimeError</h1>', html)
self.assertIn('<pre class="exception_value">Oops</pre>', html)
@@ -508,6 +508,52 @@ class ExceptionReporterTests(SimpleTestCase):
'exception occurred',
html,
)
self.assertInHTML('<li class="frame user">None</li>', html)
self.assertIn('Traceback (most recent call last):\n None', html)
text = reporter.get_traceback_text()
self.assertIn('Exception Type: RuntimeError', text)
self.assertIn('Exception Value: Oops', text)
self.assertIn('Traceback (most recent call last):\n None', text)
self.assertIn(
'During handling of the above exception (My context), another '
'exception occurred',
text,
)
def test_mid_stack_exception_without_traceback(self):
try:
try:
raise RuntimeError('Inner Oops')
except Exception as exc:
new_exc = RuntimeError('My context')
new_exc.__context__ = exc
raise RuntimeError('Oops') from new_exc
except Exception:
exc_type, exc_value, tb = sys.exc_info()
reporter = ExceptionReporter(None, exc_type, exc_value, tb)
html = reporter.get_traceback_html()
self.assertInHTML('<h1>RuntimeError</h1>', html)
self.assertIn('<pre class="exception_value">Oops</pre>', html)
self.assertIn('<th>Exception Type:</th>', html)
self.assertIn('<th>Exception Value:</th>', html)
self.assertIn('<h2>Traceback ', html)
self.assertInHTML('<li class="frame user">Traceback: None</li>', html)
self.assertIn(
'During handling of the above exception (Inner Oops), another '
'exception occurred:\n Traceback: None',
html,
)
text = reporter.get_traceback_text()
self.assertIn('Exception Type: RuntimeError', text)
self.assertIn('Exception Value: Oops', text)
self.assertIn('Traceback (most recent call last):', text)
self.assertIn(
'During handling of the above exception (Inner Oops), another '
'exception occurred:\n Traceback: None',
text,
)
def test_reporting_of_nested_exceptions(self):
request = self.rf.get('/test_view/')
@@ -671,7 +717,7 @@ class ExceptionReporterTests(SimpleTestCase):
self.assertIn('<th>Request URL:</th>', html)
self.assertNotIn('<th>Exception Type:</th>', html)
self.assertNotIn('<th>Exception Value:</th>', html)
self.assertNotIn('<h2>Traceback ', html)
self.assertIn('<h2>Traceback ', html)
self.assertIn('<h2>Request information</h2>', html)
self.assertNotIn('<p>Request data not supplied</p>', html)
@@ -684,7 +730,7 @@ class ExceptionReporterTests(SimpleTestCase):
self.assertNotIn('<th>Request URL:</th>', html)
self.assertNotIn('<th>Exception Type:</th>', html)
self.assertNotIn('<th>Exception Value:</th>', html)
self.assertNotIn('<h2>Traceback ', html)
self.assertIn('<h2>Traceback ', html)
self.assertIn('<h2>Request information</h2>', html)
self.assertIn('<p>Request data not supplied</p>', html)