Improve error handling.
This commit is contained in:
parent
af853c014c
commit
94119b4ae6
2 changed files with 15 additions and 9 deletions
|
|
@ -115,15 +115,12 @@ fn try_flake_attr(flake: &str, attr: &str) -> Result<bool> {
|
|||
fn get_store_path(nix_build_result: process::Output) -> Result<StorePath> {
|
||||
if nix_build_result.status.success() {
|
||||
String::from_utf8(nix_build_result.stdout)
|
||||
.map_err(anyhow::Error::from)
|
||||
.map_err(|e| anyhow::anyhow!(e).context("Error reading nix build output."))
|
||||
.and_then(parse_nix_build_output)
|
||||
} else {
|
||||
String::from_utf8(nix_build_result.stderr)
|
||||
.map_err(anyhow::Error::from)
|
||||
.and_then(|e| {
|
||||
log::error!("{e}");
|
||||
anyhow::bail!("Nix build failed.")
|
||||
})
|
||||
.and_then(|e| Err(anyhow::anyhow!(e).context("Nix build failed.")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
src/main.rs
17
src/main.rs
|
|
@ -183,13 +183,22 @@ fn do_generate(
|
|||
use_remote_sudo: bool,
|
||||
) -> Result<()> {
|
||||
if let Some(target_host) = target_host {
|
||||
invoke_remote_script(
|
||||
let status = invoke_remote_script(
|
||||
&store_path.store_path,
|
||||
"register-profile",
|
||||
target_host,
|
||||
use_remote_sudo,
|
||||
)?;
|
||||
Ok(())
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
anyhow::bail!(
|
||||
"Remote command exited with exit status {}",
|
||||
status
|
||||
.code()
|
||||
.map_or("unknown".to_string(), |c| c.to_string())
|
||||
)
|
||||
}
|
||||
} else {
|
||||
check_root()?;
|
||||
system_manager::generate::generate(store_path)
|
||||
|
|
@ -256,10 +265,10 @@ fn do_copy_closure(store_path: &StorePath, target_host: &str) -> Result<()> {
|
|||
.status()?;
|
||||
if status.success() {
|
||||
log::info!("Successfully copied closure to target host");
|
||||
Ok(())
|
||||
} else {
|
||||
log::error!("Error copying closure, {}", status);
|
||||
anyhow::bail!("Error copying closure, {}", status);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn invoke_remote_script(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue