diff --git a/cmk/gui/openapi/endpoints/quick_setup/response_schemas.py b/cmk/gui/openapi/endpoints/quick_setup/response_schemas.py index 69880ce0776..7fed57adb89 100644 --- a/cmk/gui/openapi/endpoints/quick_setup/response_schemas.py +++ b/cmk/gui/openapi/endpoints/quick_setup/response_schemas.py @@ -8,11 +8,23 @@ from cmk import fields -BACKGROUND_JOB_EXCEPTION = fields.String( - example="An exception message", - description="The exception message if the action was run in the background and raised " - "an unexpected exception", - allow_none=True, + +class BackgroundJobException(BaseSchema): + message = fields.String( + example="An exception message", + description="The exception message", + ) + traceback = fields.String( + example="The traceback of the background job exception", + description="The traceback of the exception", + ) + + +BACKGROUND_JOB_EXCEPTION = fields.Nested( + BackgroundJobException, + description="The exception details if the action was run in the background and raised an " + "unexpected exception", + example={}, ) @@ -211,7 +223,6 @@ class QuickSetupCompleteResponse(BaseSchema): example="http://save/url", description="The url to redirect to after saving the quicksetup", ) - all_stage_errors = fields.List( fields.Nested( Errors, @@ -222,5 +233,4 @@ class QuickSetupCompleteResponse(BaseSchema): description="A list of stage errors", example=[], ) - background_job_exception = BACKGROUND_JOB_EXCEPTION diff --git a/cmk/gui/quick_setup/handlers/setup.py b/cmk/gui/quick_setup/handlers/setup.py index b8e0941511f..427157ddea8 100644 --- a/cmk/gui/quick_setup/handlers/setup.py +++ b/cmk/gui/quick_setup/handlers/setup.py @@ -29,6 +29,7 @@ ) from cmk.gui.quick_setup.handlers.utils import ( Action, + BackgroundJobException, Button, form_spec_parse, get_stage_components_from_widget, @@ -232,7 +233,7 @@ def complete_quick_setup( class CompleteActionResult(BaseModel): all_stage_errors: Sequence[ValidationErrors] | None = None redirect_url: str | None = None - background_job_exception: str | None = None + background_job_exception: BackgroundJobException | None = None @classmethod def load_from_job_result(cls, job_id: str) -> "CompleteActionResult": @@ -325,10 +326,14 @@ def run_quick_setup_stage(self, job_interface: BackgroundProcessInterface) -> No job_interface.get_logger().debug( "Exception raised while the Quick setup stage action: %s", e ) - job_interface.send_exception(str(e)) - CompleteActionResult(background_job_exception=traceback.format_exc()).save_to_file( - job_interface.get_work_dir() - ) + exception_message = str(e) + job_interface.send_exception(exception_message) + CompleteActionResult( + background_job_exception=BackgroundJobException( + message=exception_message, + traceback=traceback.format_exc(), + ) + ).save_to_file(job_interface.get_work_dir()) def _run_quick_setup_stage(self, job_interface: BackgroundProcessInterface) -> None: job_interface.send_progress_update(_("Starting Quick setup action...")) diff --git a/cmk/gui/quick_setup/handlers/stage.py b/cmk/gui/quick_setup/handlers/stage.py index a5ac377f64c..e53991143bc 100644 --- a/cmk/gui/quick_setup/handlers/stage.py +++ b/cmk/gui/quick_setup/handlers/stage.py @@ -30,6 +30,7 @@ from cmk.gui.quick_setup.config_setups import register as register_config_setups from cmk.gui.quick_setup.handlers.utils import ( Action, + BackgroundJobException, Button, form_spec_parse, get_stage_components_from_widget, @@ -199,7 +200,7 @@ class StageActionResult(BaseModel, frozen=False): # TODO: This should be a list of widgets using only Sequence[Widget] will remove all fields # when the data is returned (this is a temporary fix) stage_recap: Sequence[Any] = field(default_factory=list) - background_job_exception: str | None = None + background_job_exception: BackgroundJobException | None = None @classmethod def load_from_job_result(cls, job_id: str) -> "StageActionResult": @@ -293,10 +294,13 @@ def run_quick_setup_stage_action(self, job_interface: BackgroundProcessInterface job_interface.get_logger().debug( "Exception raised while the Quick setup stage action: %s", e ) - job_interface.send_exception(str(e)) - StageActionResult(background_job_exception=traceback.format_exc()).save_to_file( - job_interface.get_work_dir() - ) + exception_message = str(e) + job_interface.send_exception(exception_message) + StageActionResult( + background_job_exception=BackgroundJobException( + message=exception_message, traceback=traceback.format_exc() + ) + ).save_to_file(job_interface.get_work_dir()) def _run_quick_setup_stage_action(self, job_interface: BackgroundProcessInterface) -> None: job_interface.send_progress_update(_("Starting Quick stage action...")) diff --git a/cmk/gui/quick_setup/handlers/utils.py b/cmk/gui/quick_setup/handlers/utils.py index 8603fa5994c..6c2a3e25dc8 100644 --- a/cmk/gui/quick_setup/handlers/utils.py +++ b/cmk/gui/quick_setup/handlers/utils.py @@ -6,6 +6,8 @@ from dataclasses import asdict, dataclass, field from typing import Any, cast, Iterable, Mapping, MutableMapping, MutableSequence, Sequence +from pydantic import BaseModel + from cmk.ccc.i18n import _ from cmk.gui.form_specs.vue.form_spec_visitor import ( @@ -140,3 +142,8 @@ def validate_custom_validators( ) ) return errors + + +class BackgroundJobException(BaseModel): + message: str + traceback: str