Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rust/agama-manager/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down Expand Up @@ -686,6 +688,13 @@ impl MessageHandler<message::GetLicense> for Service {
impl MessageHandler<message::RunAction> 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?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently introduced a new action to check whether the progress is empty or not. See

let is_empty = self
.

Perhaps you want to give it a try (it is available in master).


if !issues.is_empty() || !progress.is_empty() {
return Err(Error::InstallationBlocked);
}

match message.action {
Action::ConfigureL10n(config) => {
self.check_stage(Stage::Configuring).await?;
Expand Down
11 changes: 9 additions & 2 deletions rust/agama-server/src/server/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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."),
Expand Down
Loading