From 04a2746089fdf8b91df9d2125205e58cdfb3f0be Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 26 May 2023 13:12:18 +0200 Subject: [PATCH 1/4] Replace weird html elements with pre-element for displaying traceback
 HTML element displays preformatted text, in other words it displays text exactly how you send it (with newlines and whitespaces)
---
 python/nav/web/templates/500.html | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/python/nav/web/templates/500.html b/python/nav/web/templates/500.html
index ba4678e1d1..3be0e20194 100644
--- a/python/nav/web/templates/500.html
+++ b/python/nav/web/templates/500.html
@@ -37,11 +37,7 @@ 

Ouch...

View traceback
From 662d0654278c8e6fd57dc3da813c75d7316291d3 Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 26 May 2023 13:19:51 +0200 Subject: [PATCH 2/4] Use standard linebreaks in traceback when formatting exception Traceback extracted from sys.exc_info() has weird linebreaks and no whitespaces. traceback.format_exc() extracts traceback from sys.exception(), which has newlines and whitespaces that users are used to --- python/nav/django/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nav/django/views.py b/python/nav/django/views.py index 8ad4fc830b..256a8c664f 100644 --- a/python/nav/django/views.py +++ b/python/nav/django/views.py @@ -34,7 +34,7 @@ def custom_500(request): context={ 'type': type.__name__, 'value': value, - 'traceback': traceback.format_exception(type, value, tb), + 'traceback': traceback.format_exc(), }, request=request, ) From a3d31fe0e1f438632f10985502147a5d455571a4 Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 26 May 2023 13:21:16 +0200 Subject: [PATCH 3/4] Cleanup redundant values in custom_500 --- python/nav/django/views.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/nav/django/views.py b/python/nav/django/views.py index 256a8c664f..4e0fb4e017 100644 --- a/python/nav/django/views.py +++ b/python/nav/django/views.py @@ -27,13 +27,9 @@ def custom_500(request): template = loader.get_template('500.html') - type, value, tb = sys.exc_info() - return HttpResponseServerError( template.render( context={ - 'type': type.__name__, - 'value': value, 'traceback': traceback.format_exc(), }, request=request, From 06fd68df6665be7f3cff34b5403170b1da357afe Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 26 May 2023 13:58:12 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81974d1276..33c4784610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ found in the [HISTORY](HISTORY) file. - Handle invalid IP address input in ipdevinfo device searches gracefully, rather then crashing with a 500 error ([#2589](https://github.com/Uninett/nav/issues/2589), [#2590](https://github.com/Uninett/nav/pull/2590)) - Fix broken links to room details from room report for rooms with spaces in their names ([#2592](https://github.com/Uninett/nav/issues/2592), [#2593](https://github.com/Uninett/nav/pull/2593)) - Catch Validation error in filtering of prefixes in API ([#2606](https://github.com/Uninett/nav/issues/2606), [#2608](https://github.com/Uninett/nav/pull/2608)) +- Redesign the 500 Error page so that the exception traceback if formatted as one ## [5.6.0] - 2023-01-20