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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-12-28 13:22:54 -08:00 committed by Veiko Aasa
parent 26d317bfd5
commit 5cf89ad85c
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
2 changed files with 2 additions and 21 deletions

View File

@ -25,16 +25,6 @@
{% if results %}
{% include "diagnostics_results.html" with results=results %}
{% elif exception %}
<div class="alert alert-danger d-flex align-items-center" role="alert">
<div class="me-2">
<span class="fa fa-exclamation-triangle" aria-hidden="true"></span>
<span class="visually-hidden">{% trans "Caution:" %}</span>
</div>
<div>
{{ exception }}
</div>
</div>
{% else %}
<p>{% trans "This app does not support diagnostics" %}</p>
{% endif %}

View File

@ -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,
})