diff --git a/rust/agama-manager/src/service.rs b/rust/agama-manager/src/service.rs index 3be84f361e..d5fa8ab86f 100644 --- a/rust/agama-manager/src/service.rs +++ b/rust/agama-manager/src/service.rs @@ -85,6 +85,8 @@ pub enum Error { Hardware(#[from] hardware::Error), #[error("Cannot dispatch this action in {current} stage (expected {expected}).")] UnexpectedStage { current: Stage, expected: Stage }, + #[error("Cannot start the installation. The config contains some issues.")] + InstallationBlocked, #[error(transparent)] Users(#[from] users::service::Error), } @@ -686,6 +688,13 @@ impl MessageHandler for Service { impl MessageHandler for Service { /// It runs the given action. async fn handle(&mut self, message: message::RunAction) -> Result<(), Error> { + let issues = self.issues.call(issue::message::Get).await?; + let progress = self.progress.call(progress::message::GetProgress).await?; + + if !issues.is_empty() || !progress.is_empty() { + return Err(Error::InstallationBlocked); + } + match message.action { Action::ConfigureL10n(config) => { self.check_stage(Stage::Configuring).await?; diff --git a/rust/agama-server/src/server/web.rs b/rust/agama-server/src/server/web.rs index d5c3883b05..8365fdc9e0 100644 --- a/rust/agama-server/src/server/web.rs +++ b/rust/agama-server/src/server/web.rs @@ -22,6 +22,7 @@ use crate::server::config_schema; use agama_lib::{error::ServiceError, logs}; +use agama_manager::service::Error::InstallationBlocked; use agama_manager::{self as manager, message}; use agama_software::Resolvable; use agama_utils::{ @@ -66,7 +67,12 @@ impl IntoResponse for Error { let body = json!({ "error": self.to_string() }); - (StatusCode::BAD_REQUEST, Json(body)).into_response() + let status = if matches!(self, Error::Manager(InstallationBlocked)) { + StatusCode::UNPROCESSABLE_ENTITY + } else { + StatusCode::BAD_REQUEST + }; + (status, Json(body)).into_response() } } @@ -398,7 +404,8 @@ async fn get_license( context_path = "/api/v2", responses( (status = 200, description = "Action successfully run."), - (status = 400, description = "Not possible to run the action.", body = Object) + (status = 400, description = "Not possible to run the action.", body = Object), + (status = 422, description = "Action blocked by backend state", body = Object) ), params( ("action" = Action, description = "Description of the action to run."),