Skip to content

Commit

Permalink
Better error handling when unit file location can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Aug 30, 2024
1 parent f36b1e0 commit cfe9cf4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/systemd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// File initially taken from https://github.com/servicer-labs/servicer/blob/master/src/utils/systemd.rs, since modified

use core::str;
use std::process::Command;

use anyhow::{bail, Result};
Expand Down Expand Up @@ -176,7 +177,10 @@ pub fn get_unit_file_location(service: &UnitId) -> Result<String> {
let output = Command::new("systemctl").args(&args).output()?;

if output.status.success() {
let path = String::from_utf8(output.stdout)?;
let path = str::from_utf8(&output.stdout)?.trim();
if path.is_empty() {
bail!("No unit file found for {}", service.name);
}
Ok(path.trim().to_string())
} else {
let stderr = String::from_utf8(output.stderr)?;
Expand Down

0 comments on commit cfe9cf4

Please sign in to comment.