mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(operations): a job's unexpected error is not shown raw; the log has its traceback
A job that failed on an exception that is not libvirt's or a refusal showed its raw text to users (a SQL error such as "UNIQUE constraint failed: instances_instance.uuid", a KeyError's key), and the worker logged only that text. Users now read "The panel failed unexpectedly; its log has the details." and the worker logs the exception with its traceback. A live clone whose recovery found the clone made but could not thaw the source's file systems kept that in the error of a succeeded job, which the job panel does not show. It is a warning of the clone's result, as when the job itself made the clone.
This commit is contained in:
parent
d1fb9bd2d4
commit
432b1505b3
10 changed files with 375 additions and 277 deletions
|
|
@ -7,6 +7,7 @@ the Settings page. The worker reads them itself (the settings middleware only
|
|||
runs in gunicorn)."""
|
||||
|
||||
import re
|
||||
import traceback
|
||||
|
||||
import libvirt
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
|
@ -121,6 +122,27 @@ def public_error_text(exception):
|
|||
return words(public_error(exception))
|
||||
|
||||
|
||||
# not libvirt's error or a refusal (whose text is for users) but a fault of
|
||||
# the panel: its text (a SQL error, a KeyError's key) tells users nothing
|
||||
UNEXPECTED = gettext_noop("The panel failed unexpectedly; its log has the details.")
|
||||
REPORTED = (libvirtError, PermissionDenied, Http404, ValueError)
|
||||
|
||||
|
||||
def traceback_of(err):
|
||||
"""A fault of the panel, also one a reported error wraps, goes to the log
|
||||
with its traceback, without secrets as the message (exc_info would write
|
||||
them); a reported error says enough."""
|
||||
fault = err.__cause__ if isinstance(err, REPORTED) else err
|
||||
if fault is None or isinstance(fault, REPORTED):
|
||||
return ""
|
||||
return "\n" + safe_text("".join(traceback.format_exception(err)))
|
||||
|
||||
|
||||
def job_error(err):
|
||||
"""What users read of a job's exception."""
|
||||
return public_error(err) if isinstance(err, REPORTED) else say(UNEXPECTED)
|
||||
|
||||
|
||||
def check_params(params):
|
||||
if isinstance(params, dict):
|
||||
for key, value in params.items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue