Skip to content

Commit

Permalink
imageproxy: introduce SkopeoSpawnError to improve UX
Browse files Browse the repository at this point in the history
This commit adds a new SkopeoSpawnError that helps with tweaking
the user-experience when e.g. skopeo is not installed.

Partially closes:
containers/composefs-rs#59

Signed-off-by: Michael Vogt <[email protected]>
  • Loading branch information
mvo5 committed Jan 17, 2025
1 parent 03bc43e commit 8f992d3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/imageproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum Error {
#[error("i/o error")]
/// An input/output error
Io(#[from] std::io::Error),
#[error("skopeo spawn error: {}", .0)]
/// An error spawning skopeo
SkopeoSpawnError(#[source] std::io::Error),
#[error("serialization error")]
/// Returned when serialization or deserialization fails
SerDe(#[from] serde_json::Error),
Expand Down Expand Up @@ -324,7 +327,10 @@ impl ImageProxy {
None,
)?;
c.stdin(Stdio::from(theirsock));
let child = c.spawn()?;
let child = match c.spawn() {
Ok(c) => c,
Err(error) => return Err(Error::SkopeoSpawnError(error)),
};
tracing::debug!("Spawned skopeo pid={:?}", child.id());
// Here we use std sync API via thread because tokio installs
// a SIGCHLD handler which can conflict with e.g. the glib one
Expand Down Expand Up @@ -687,4 +693,19 @@ mod tests {
.unwrap();
validate(c, &["--authfile", "/proc/self/fd/100"], &[]);
}

#[tokio::test]
async fn skopeo_not_found() {
let mut config = ImageProxyConfig {
..ImageProxyConfig::default()
};
config.skopeo_cmd = Some(Command::new("no-skopeo"));

let res = ImageProxy::new_with_config(config).await;
assert!(matches!(res, Err(Error::SkopeoSpawnError(_))));
assert_eq!(
res.err().unwrap().to_string(),
"skopeo spawn error: No such file or directory (os error 2)"
);
}
}

0 comments on commit 8f992d3

Please sign in to comment.