Skip to content

Commit

Permalink
Merge pull request #17 from jplatte/command-error
Browse files Browse the repository at this point in the history
Abort installation if a process spawned by lichen fails
  • Loading branch information
ikeycode authored Sep 12, 2024
2 parents a077ba4 + b7fe4b4 commit d09e897
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions crates/installer/src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

//! Lichen installation steps
use std::{fmt::Debug, process::ExitStatus};
use thiserror::Error;

mod context;
pub use context::Context;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
Expand All @@ -18,6 +20,9 @@ pub enum Error {

#[error("no mountpoint given")]
NoMountpoint,

#[error("command `{program}` exited with {status}")]
CommandFailed { program: String, status: ExitStatus },
}

#[derive(Debug)]
Expand Down Expand Up @@ -155,7 +160,6 @@ impl<'a> Step<'a> {
}

mod partitions;
use std::fmt::Debug;

pub use partitions::{BindMount, FormatPartition, MountPartition, Unmount};

Expand Down
6 changes: 5 additions & 1 deletion lichen_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ impl<'a> Context<'a> for CliContext {
/// Run a step command
/// Right now all output is dumped to stdout/stderr
fn run_command(&self, cmd: &mut Command) -> Result<(), installer::steps::Error> {
let _ = cmd.spawn()?.wait();
let status = cmd.spawn()?.wait()?;
if !status.success() {
let program = cmd.get_program().to_string_lossy().into();
return Err(installer::steps::Error::CommandFailed { program, status });
}
Ok(())
}

Expand Down

0 comments on commit d09e897

Please sign in to comment.