diff options
Diffstat (limited to 'src/image.rs')
-rw-r--r-- | src/image.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/image.rs b/src/image.rs index 62f80f7..7b7c2ce 100644 --- a/src/image.rs +++ b/src/image.rs @@ -12,9 +12,13 @@ pub enum ImageError { #[error("qemu-img resize failed: {0}")] ResizeError(String), - /// I/O error. - #[error(transparent)] - IoError(#[from] std::io::Error), + /// Base image copy error. + #[error("could not copy base image {0} to {1}")] + BaseImageCopy(PathBuf, PathBuf, #[source] std::io::Error), + + /// Could not execute command. + #[error("couldn't execute {0}: {1}")] + CommandError(String, #[source] std::io::Error), /// Error parsing a string as UTF8. #[error(transparent)] @@ -30,7 +34,9 @@ pub struct VirtualMachineImage { impl VirtualMachineImage { /// Create new image from a base image. pub fn new_from_base(base_image: &Path, image: &Path) -> Result<Self, ImageError> { - copy(base_image, image)?; + copy(base_image, image).map_err(|err| { + ImageError::BaseImageCopy(base_image.to_path_buf(), image.to_path_buf(), err) + })?; Ok(Self { filename: image.to_path_buf(), }) @@ -47,7 +53,8 @@ impl VirtualMachineImage { .arg("resize") .arg(self.filename()) .arg(format!("{}", new_size)) - .output()?; + .output() + .map_err(|err| ImageError::CommandError("qemu-img resize".to_string(), err))?; if !r.status.success() { let stderr = String::from_utf8(r.stderr)?; return Err(ImageError::ResizeError(stderr)); |