summaryrefslogtreecommitdiff
path: root/src/image.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-25 09:37:15 +0000
committerLars Wirzenius <liw@liw.fi>2021-03-25 09:37:15 +0000
commita45450a42e4cdcd7f2d5671984c9c7f3945131fd (patch)
tree27e9b77e04a877a3efdb7b9795f5977060b3488a /src/image.rs
parent8e6febfb777714c5b7f5ed9843e660ef218d3eb0 (diff)
parent23138e5bdb8ca751834009d99d85b37e5e4ae5ae (diff)
downloadvmadm-a45450a42e4cdcd7f2d5671984c9c7f3945131fd.tar.gz
Merge branch 'errors' into 'main'
subplot fix and error message improvements Closes #14 See merge request larswirzenius/vmadm!29
Diffstat (limited to 'src/image.rs')
-rw-r--r--src/image.rs17
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));