Add GetTenantError::NotActivated

This commit is contained in:
Konstantin Knizhnik
2023-06-04 09:38:00 +03:00
parent e4b345a3c1
commit 1178dbc614
4 changed files with 12 additions and 3 deletions

View File

@@ -162,6 +162,9 @@ impl From<GetTenantError> for ApiError {
e @ GetTenantError::NotLoaded(_, _) => {
ApiError::InternalServerError(anyhow::Error::new(e))
}
e @ GetTenantError::NotActivated(_, _) => {
ApiError::InternalServerError(anyhow::Error::new(e))
}
}
}
}

View File

@@ -1180,6 +1180,9 @@ async fn get_active_tenant_with_timeout(
Ok(tenant) => tenant,
Err(e @ GetTenantError::NotFound(_)) => return Err(GetActiveTenantError::NotFound(e)),
Err(e @ GetTenantError::NotLoaded(_, _)) => return Err(GetActiveTenantError::NotFound(e)),
Err(e @ GetTenantError::NotActivated(_, _)) => {
return Err(GetActiveTenantError::NotFound(e))
}
Err(GetTenantError::NotActive(_)) => {
unreachable!("we're calling get_tenant with active=false")
}

View File

@@ -459,7 +459,7 @@ struct RemoteStartupData {
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum WaitToBecomeActiveError {
pub enum WaitToBecomeActiveError {
WillNotBecomeActive {
tenant_id: TenantId,
state: TenantState,

View File

@@ -22,6 +22,7 @@ use crate::task_mgr::{self, TaskKind};
use crate::tenant::config::TenantConfOpt;
use crate::tenant::{
create_tenant_files, CreateTenantFilesMode, SetStoppingError, Tenant, TenantState,
WaitToBecomeActiveError,
};
use crate::IGNORED_TENANT_FILE_NAME;
@@ -68,7 +69,7 @@ impl LazyTenantsMap {
tenant
.wait_to_become_active()
.await
.map_err(|_| GetTenantError::NotActive(*tenant_id))?;
.map_err(|e| GetTenantError::NotActivated(*tenant_id, e))?;
}
Ok(tenant)
}
@@ -493,8 +494,10 @@ pub enum GetTenantError {
NotFound(TenantId),
#[error("Tenant {0} is not active")]
NotActive(TenantId),
#[error("Tenant {0} can not be loaded")]
#[error("Tenant {0} can not be loaded: {1}")]
NotLoaded(TenantId, anyhow::Error),
#[error("Tenant {0} can not be activated: {1}")]
NotActivated(TenantId, WaitToBecomeActiveError),
}
/// Gets the tenant from the in-memory data, erroring if it's absent or is not fitting to the query.