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> {
|
fn get_store_path(nix_build_result: process::Output) -> Result<StorePath> {
|
||||||
if nix_build_result.status.success() {
|
if nix_build_result.status.success() {
|
||||||
String::from_utf8(nix_build_result.stdout)
|
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)
|
.and_then(parse_nix_build_output)
|
||||||
} else {
|
} else {
|
||||||
String::from_utf8(nix_build_result.stderr)
|
String::from_utf8(nix_build_result.stderr)
|
||||||
.map_err(anyhow::Error::from)
|
.map_err(anyhow::Error::from)
|
||||||
.and_then(|e| {
|
.and_then(|e| Err(anyhow::anyhow!(e).context("Nix build failed.")))
|
||||||
log::error!("{e}");
|
|
||||||
anyhow::bail!("Nix build failed.")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
17
src/main.rs
17
src/main.rs
|
|
@ -183,13 +183,22 @@ fn do_generate(
|
||||||
use_remote_sudo: bool,
|
use_remote_sudo: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some(target_host) = target_host {
|
if let Some(target_host) = target_host {
|
||||||
invoke_remote_script(
|
let status = invoke_remote_script(
|
||||||
&store_path.store_path,
|
&store_path.store_path,
|
||||||
"register-profile",
|
"register-profile",
|
||||||
target_host,
|
target_host,
|
||||||
use_remote_sudo,
|
use_remote_sudo,
|
||||||
)?;
|
)?;
|
||||||
|
if status.success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
anyhow::bail!(
|
||||||
|
"Remote command exited with exit status {}",
|
||||||
|
status
|
||||||
|
.code()
|
||||||
|
.map_or("unknown".to_string(), |c| c.to_string())
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
check_root()?;
|
check_root()?;
|
||||||
system_manager::generate::generate(store_path)
|
system_manager::generate::generate(store_path)
|
||||||
|
|
@ -256,10 +265,10 @@ fn do_copy_closure(store_path: &StorePath, target_host: &str) -> Result<()> {
|
||||||
.status()?;
|
.status()?;
|
||||||
if status.success() {
|
if status.success() {
|
||||||
log::info!("Successfully copied closure to target host");
|
log::info!("Successfully copied closure to target host");
|
||||||
} else {
|
|
||||||
log::error!("Error copying closure, {}", status);
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("Error copying closure, {}", status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invoke_remote_script(
|
fn invoke_remote_script(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue