Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error when someone tries to start an unknown service #431

Merged
merged 1 commit into from
Oct 27, 2022
Merged
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
26 changes: 25 additions & 1 deletion iroh/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ async fn start_services(api: &impl Api, services: HashSet<&str>) -> Result<()> {
// check for any running iroh services
let table = api.check().await;

let mut expected_services = HashSet::new();
let expected_services = table
.iter()
.fold(&mut expected_services, |accum, status_row| {
match status_row.status() {
iroh_api::ServiceStatus::ServiceUnknown => (),
_ => {
accum.insert(status_row.name());
}
}
accum
});

let unknown_services: HashSet<&str> = services.difference(expected_services).copied().collect();

if !unknown_services.is_empty() {
let u = unknown_services.into_iter().collect::<Vec<&str>>();
let mut e = "Unknown services";
if u.len() == 1 {
e = "Unknown service";
}
return Err(anyhow!("{} {}.", e, u.join(", ")));
}

let mut missing_services = HashSet::new();
let missing_services = table
.iter()
Expand Down Expand Up @@ -67,7 +91,7 @@ async fn start_services(api: &impl Api, services: HashSet<&str>) -> Result<()> {
if missing_services.is_empty() {
println!(
"{}",
"All iroh daemons are already running. all systems nominal.".green()
"All iroh daemons are already running. all systems normal.".green()
);
return Ok(());
}
Expand Down