Skip to content

Commit

Permalink
nix::info: handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Aug 7, 2023
1 parent cd2192f commit ff938a9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/nix/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ pub struct NixInfo {
#[server(GetNixInfo, "/api")]
pub async fn get_nix_info() -> Result<NixInfo, ServerFnError> {
use tokio::process::Command;
let out = Command::new("nix").arg("--version").output().await?.stdout;
// TODO: Parse the version string
let nix_version = String::from_utf8(out)
.map_err(|e| <std::string::FromUtf8Error as Into<ServerFnError>>::into(e))?;
Ok(NixInfo { nix_version })
let out = Command::new("nix").arg("--version").output().await?;
if out.status.success() {
// TODO: Parse the version string
let nix_version = String::from_utf8(out.stdout)
.map_err(|e| <std::string::FromUtf8Error as Into<ServerFnError>>::into(e))?;
Ok(NixInfo { nix_version })
} else {
Err(ServerFnError::ServerError(
"Unable to determine nix version".into(),
))
}
}

impl IntoView for NixInfo {
Expand Down

0 comments on commit ff938a9

Please sign in to comment.