improve the output of some errors and plans (#66)
* improve the output of some errors and plans * speeling
This commit is contained in:
parent
7cc71f1ccd
commit
f1d12149de
|
@ -29,7 +29,7 @@ impl CreateGroup {
|
|||
#[typetag::serde(name = "create_group")]
|
||||
impl Action for CreateGroup {
|
||||
fn tracing_synopsis(&self) -> String {
|
||||
format!("Create group `{}` with GID `{}`", self.name, self.gid)
|
||||
format!("Create group `{}` (GID {})", self.name, self.gid)
|
||||
}
|
||||
fn execute_description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
|
@ -111,11 +111,11 @@ impl Action for CreateGroup {
|
|||
fn revert_description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
name,
|
||||
gid: _,
|
||||
gid,
|
||||
action_state: _,
|
||||
} = &self;
|
||||
vec![ActionDescription::new(
|
||||
format!("Delete group {name}"),
|
||||
format!("Delete group `{name}` (GID {gid})"),
|
||||
vec![format!(
|
||||
"The nix daemon requires a system user group its system users can be part of"
|
||||
)],
|
||||
|
|
|
@ -34,7 +34,7 @@ impl CreateUser {
|
|||
impl Action for CreateUser {
|
||||
fn tracing_synopsis(&self) -> String {
|
||||
format!(
|
||||
"Create user `{}` with UID `{}` with group `{}` (GID {})",
|
||||
"Create user `{}` (UID {}) in group `{}` (GID {})",
|
||||
self.name, self.uid, self.groupname, self.gid
|
||||
)
|
||||
}
|
||||
|
@ -219,16 +219,11 @@ impl Action for CreateUser {
|
|||
}
|
||||
|
||||
fn revert_description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
name,
|
||||
uid,
|
||||
groupname: _,
|
||||
gid,
|
||||
action_state: _,
|
||||
} = self;
|
||||
|
||||
vec![ActionDescription::new(
|
||||
format!("Delete user {name} with UID {uid} with group {gid}"),
|
||||
format!(
|
||||
"Delete user `{}` (UID {}) in group {} (GID {})",
|
||||
self.name, self.uid, self.groupname, self.gid
|
||||
),
|
||||
vec![format!(
|
||||
"The nix daemon requires system users it can act as in order to build"
|
||||
)],
|
||||
|
|
|
@ -176,7 +176,13 @@ pub enum ConfigureShellProfileError {
|
|||
#[source]
|
||||
CreateOrAppendFileError,
|
||||
),
|
||||
#[error("Multiple errors: {}", .0.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(" & "))]
|
||||
#[error("Multiple errors: {}", .0.iter().map(|v| {
|
||||
if let Some(source) = v.source() {
|
||||
format!("{v} ({source})")
|
||||
} else {
|
||||
format!("{v}")
|
||||
}
|
||||
}).collect::<Vec<_>>().join(" & "))]
|
||||
MultipleCreateOrAppendFile(Vec<Box<dyn std::error::Error + Send + Sync>>),
|
||||
#[error("Joining spawned async task")]
|
||||
Join(
|
||||
|
|
|
@ -56,31 +56,42 @@ impl CreateUsersAndGroup {
|
|||
#[typetag::serde(name = "create_users_and_group")]
|
||||
impl Action for CreateUsersAndGroup {
|
||||
fn tracing_synopsis(&self) -> String {
|
||||
"Create build users and group".to_string()
|
||||
format!(
|
||||
"Create build users (UID {}-{}) and group (GID {})",
|
||||
self.nix_build_user_id_base,
|
||||
self.nix_build_user_id_base + self.daemon_user_count,
|
||||
self.nix_build_group_id
|
||||
)
|
||||
}
|
||||
|
||||
fn execute_description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
daemon_user_count,
|
||||
nix_build_group_name,
|
||||
nix_build_group_id,
|
||||
nix_build_user_prefix,
|
||||
nix_build_user_id_base,
|
||||
create_group: _,
|
||||
create_users: _,
|
||||
daemon_user_count: _,
|
||||
nix_build_group_name: _,
|
||||
nix_build_group_id: _,
|
||||
nix_build_user_prefix: _,
|
||||
nix_build_user_id_base: _,
|
||||
create_group,
|
||||
create_users,
|
||||
action_state: _,
|
||||
} = &self;
|
||||
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
self.tracing_synopsis(),
|
||||
vec![
|
||||
format!("The nix daemon requires system users (and a group they share) which it can act as in order to build"),
|
||||
format!("Create group `{nix_build_group_name}` with uid `{nix_build_group_id}`"),
|
||||
format!("Create {daemon_user_count} users with prefix `{nix_build_user_prefix}` starting at uid `{nix_build_user_id_base}`"),
|
||||
],
|
||||
)
|
||||
]
|
||||
let mut create_users_descriptions = Vec::new();
|
||||
for create_user in create_users {
|
||||
if let Some(val) = create_user.describe_execute().iter().next() {
|
||||
create_users_descriptions.push(val.description.clone())
|
||||
}
|
||||
}
|
||||
|
||||
let mut explanation = vec![
|
||||
format!("The nix daemon requires system users (and a group they share) which it can act as in order to build"),
|
||||
];
|
||||
if let Some(val) = create_group.describe_execute().iter().next() {
|
||||
explanation.push(val.description.clone())
|
||||
}
|
||||
explanation.append(&mut create_users_descriptions);
|
||||
|
||||
vec![ActionDescription::new(self.tracing_synopsis(), explanation)]
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(
|
||||
|
@ -106,57 +117,83 @@ impl Action for CreateUsersAndGroup {
|
|||
create_group.try_execute().await?;
|
||||
|
||||
// Mac is apparently not threadsafe here...
|
||||
for create_user in create_users.iter_mut() {
|
||||
// let mut create_user_clone = create_user.clone();
|
||||
// let _abort_handle = set.spawn(async move {
|
||||
create_user.try_execute().await?;
|
||||
// Result::<_, CreateUserError>::Ok((idx, create_user_clone))
|
||||
// });
|
||||
}
|
||||
use target_lexicon::OperatingSystem;
|
||||
match OperatingSystem::host() {
|
||||
OperatingSystem::MacOSX {
|
||||
major: _,
|
||||
minor: _,
|
||||
patch: _,
|
||||
}
|
||||
| OperatingSystem::Darwin => {
|
||||
for create_user in create_users.iter_mut() {
|
||||
create_user.try_execute().await?;
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let mut set = JoinSet::new();
|
||||
let mut errors: Vec<Box<dyn std::error::Error + Send + Sync>> = Vec::new();
|
||||
for (idx, create_user) in create_users.iter_mut().enumerate() {
|
||||
let mut create_user_clone = create_user.clone();
|
||||
let _abort_handle = set.spawn(async move {
|
||||
create_user_clone.try_execute().await?;
|
||||
Result::<_, _>::Ok((idx, create_user_clone))
|
||||
});
|
||||
}
|
||||
|
||||
// while let Some(result) = set.join_next().await {
|
||||
// match result {
|
||||
// Ok(Ok((idx, success))) => create_users[idx] = success,
|
||||
// Ok(Err(e)) => errors.push(e),
|
||||
// Err(e) => return Err(e)?,
|
||||
// };
|
||||
// }
|
||||
while let Some(result) = set.join_next().await {
|
||||
match result {
|
||||
Ok(Ok((idx, success))) => create_users[idx] = success,
|
||||
Ok(Err(e)) => errors.push(e),
|
||||
Err(e) => return Err(e)?,
|
||||
};
|
||||
}
|
||||
|
||||
// if !errors.is_empty() {
|
||||
// if errors.len() == 1 {
|
||||
// return Err(errors.into_iter().next().unwrap().into());
|
||||
// } else {
|
||||
// return Err(CreateUsersAndGroupError::CreateUsers(errors));
|
||||
// }
|
||||
// }
|
||||
if !errors.is_empty() {
|
||||
if errors.len() == 1 {
|
||||
return Err(errors.into_iter().next().unwrap().into());
|
||||
} else {
|
||||
return Err(CreateUsersAndGroupError::CreateUsers(errors).boxed());
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn revert_description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
daemon_user_count,
|
||||
nix_build_group_name,
|
||||
nix_build_group_id,
|
||||
nix_build_user_prefix,
|
||||
nix_build_user_id_base,
|
||||
create_group: _,
|
||||
create_users: _,
|
||||
daemon_user_count: _,
|
||||
nix_build_group_name: _,
|
||||
nix_build_group_id: _,
|
||||
nix_build_user_prefix: _,
|
||||
nix_build_user_id_base: _,
|
||||
create_group,
|
||||
create_users,
|
||||
action_state: _,
|
||||
} = &self;
|
||||
if self.action_state == ActionState::Uncompleted {
|
||||
vec![]
|
||||
} else {
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
format!("Remove build users and group"),
|
||||
vec![
|
||||
format!("The nix daemon requires system users (and a group they share) which it can act as in order to build"),
|
||||
format!("Create group `{nix_build_group_name}` with uid `{nix_build_group_id}`"),
|
||||
format!("Create {daemon_user_count} users with prefix `{nix_build_user_prefix}` starting at uid `{nix_build_user_id_base}`"),
|
||||
],
|
||||
)
|
||||
]
|
||||
let mut create_users_descriptions = Vec::new();
|
||||
for create_user in create_users {
|
||||
if let Some(val) = create_user.describe_revert().iter().next() {
|
||||
create_users_descriptions.push(val.description.clone())
|
||||
}
|
||||
}
|
||||
|
||||
let mut explanation = vec![
|
||||
format!("The nix daemon requires system users (and a group they share) which it can act as in order to build"),
|
||||
];
|
||||
if let Some(val) = create_group.describe_revert().iter().next() {
|
||||
explanation.push(val.description.clone())
|
||||
}
|
||||
explanation.append(&mut create_users_descriptions);
|
||||
|
||||
vec![ActionDescription::new(
|
||||
format!("Remove Nix users and group"),
|
||||
explanation,
|
||||
)]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +266,13 @@ pub enum CreateUsersAndGroupError {
|
|||
#[from]
|
||||
CreateUserError,
|
||||
),
|
||||
#[error("Multiple errors: {}", .0.iter().map(|v| format!("{v}")).collect::<Vec<_>>().join(" & "))]
|
||||
#[error("Multiple errors: {}", .0.iter().map(|v| {
|
||||
if let Some(source) = v.source() {
|
||||
format!("{v} ({source})")
|
||||
} else {
|
||||
format!("{v}")
|
||||
}
|
||||
}).collect::<Vec<_>>().join(" & "))]
|
||||
CreateUsers(Vec<Box<dyn std::error::Error + Send + Sync>>),
|
||||
#[error("Creating group")]
|
||||
CreateGroup(
|
||||
|
|
Loading…
Reference in a new issue