Correctly expected error in default planner if nix installed (#151)

* Correctly expected error in default planner if nix installed

* fixup
This commit is contained in:
Ana Hobden 2023-01-04 09:32:45 -08:00 committed by GitHub
parent 55906e15bb
commit e27d01f221
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 12 deletions

View file

@ -80,13 +80,16 @@ impl CommandExecute for Install {
match existing_receipt {
Some(existing_receipt) => {
if existing_receipt.planner.typetag_name() != chosen_planner.typetag_name() {
return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install"))
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install").red());
return Ok(ExitCode::FAILURE)
}
if existing_receipt.planner.settings().map_err(|e| eyre!(e))? != chosen_planner.settings().map_err(|e| eyre!(e))? {
return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install"))
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install").red());
return Ok(ExitCode::FAILURE)
}
if existing_receipt.actions.iter().all(|v| v.state == ActionState::Completed) {
return Err(eyre!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working"))
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working").red());
return Ok(ExitCode::FAILURE)
}
existing_receipt
} ,
@ -105,6 +108,23 @@ impl CommandExecute for Install {
let builtin_planner = BuiltinPlanner::from_common_settings(settings)
.await
.map_err(|e| eyre::eyre!(e))?;
match existing_receipt {
Some(existing_receipt) => {
if existing_receipt.planner.typetag_name() != builtin_planner.typetag_name() {
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used a different planner, try uninstalling the existing install").red());
return Ok(ExitCode::FAILURE)
}
if existing_receipt.planner.settings().map_err(|e| eyre!(e))? != builtin_planner.settings().map_err(|e| eyre!(e))? {
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}` which used different planner settings, try uninstalling the existing install").red());
return Ok(ExitCode::FAILURE)
}
if existing_receipt.actions.iter().all(|v| v.state == ActionState::Completed) {
eprintln!("{}", format!("Found existing plan in `{RECEIPT_LOCATION}`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working").red());
return Ok(ExitCode::FAILURE)
}
existing_receipt
},
None => {
let res = builtin_planner.plan().await;
match res {
Ok(plan) => plan,
@ -117,6 +137,8 @@ impl CommandExecute for Install {
}
}
},
}
},
(Some(_), Some(_)) => return Err(eyre!("`--plan` conflicts with passing a planner, a planner creates plans, so passing an existing plan doesn't make sense")),
};

View file

@ -168,6 +168,22 @@ impl BuiltinPlanner {
BuiltinPlanner::SteamDeck(i) => i.boxed(),
}
}
pub fn typetag_name(&self) -> &'static str {
match self {
BuiltinPlanner::LinuxMulti(i) => i.typetag_name(),
BuiltinPlanner::DarwinMulti(i) => i.typetag_name(),
BuiltinPlanner::SteamDeck(i) => i.typetag_name(),
}
}
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
match self {
BuiltinPlanner::LinuxMulti(i) => i.settings(),
BuiltinPlanner::DarwinMulti(i) => i.settings(),
BuiltinPlanner::SteamDeck(i) => i.settings(),
}
}
}
/// An error originating from a [`Planner`]