From 5cf89ad85cf4fd7c36e3ae835749c71d577245b1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 28 Dec 2024 13:22:54 -0800 Subject: [PATCH] diagnostics: Use generic handler to handle exceptions in diagnostics - Currently, if an error occurred during diagnostics, just error message (without traceback details) was supposed to be shown on the results page. However, due to a bug in code related to showing repair button, a separate exception is raised. - Simplify the code by dropping all custom error display. Instead allow the generic error display mechanism in the middleware to handle the error. This keeps the code simple. Tests: - Raise an exception in diagnose() method of the 'users' app. Run the diagnostics for the users app. Notice that Diagnostics app page is shown with error alert containing full traceback details. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- .../diagnostics/templates/diagnostics_app.html | 10 ---------- plinth/modules/diagnostics/views.py | 13 ++----------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/plinth/modules/diagnostics/templates/diagnostics_app.html b/plinth/modules/diagnostics/templates/diagnostics_app.html index 3b3d6e872..c2665ccff 100644 --- a/plinth/modules/diagnostics/templates/diagnostics_app.html +++ b/plinth/modules/diagnostics/templates/diagnostics_app.html @@ -25,16 +25,6 @@ {% if results %} {% include "diagnostics_results.html" with results=results %} - {% elif exception %} - {% else %}

{% trans "This app does not support diagnostics" %}

{% endif %} diff --git a/plinth/modules/diagnostics/views.py b/plinth/modules/diagnostics/views.py index f3a73f2be..bac8c0b2d 100644 --- a/plinth/modules/diagnostics/views.py +++ b/plinth/modules/diagnostics/views.py @@ -103,17 +103,9 @@ def diagnose_app(request, app_id): app = App.get(app_id) except KeyError: raise Http404('App does not exist') + app_name = app.info.name or app_id - - diagnosis = None - diagnosis_exception = None - try: - diagnosis = app.diagnose() - except Exception as exception: - logger.exception('Error running %s diagnostics - %s', app_id, - exception) - diagnosis_exception = str(exception) - + diagnosis = app.diagnose() show_repair = False for check in diagnosis: if check.result in [Result.FAILED, Result.WARNING]: @@ -126,7 +118,6 @@ def diagnose_app(request, app_id): 'app_id': app_id, 'app_name': app_name, 'results': diagnosis, - 'exception': diagnosis_exception, 'show_repair': show_repair, })