Skip to content

Commit

Permalink
chore: add thiserror::Error for DriveError
Browse files Browse the repository at this point in the history
replace Displ implementation with thiserror::Error.

Signed-off-by: Diana Popa <[email protected]>
  • Loading branch information
dianpopa committed Feb 2, 2023
1 parent d02bf98 commit af3207c
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/vmm/src/vmm_config/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use std::collections::VecDeque;
use std::convert::TryInto;
use std::fmt::{Display, Formatter};
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
Expand All @@ -18,35 +17,27 @@ use serde::{Deserialize, Serialize};
use super::RateLimiterConfig;
use crate::Error as VmmError;

type Result<T> = result::Result<T, DriveError>;

/// Errors associated with the operations allowed on a drive.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum DriveError {
/// Could not create a Block Device.
#[error("Unable to create the block device: {0:?}")]
CreateBlockDevice(BlockError),
/// Failed to create a `RateLimiter` object.
#[error("Cannot create RateLimiter: {0}")]
CreateRateLimiter(io::Error),
/// Error during block device update (patch).
#[error("Unable to patch the block device: {0}")]
DeviceUpdate(VmmError),
/// The block device path is invalid.
#[error("Invalid block device path: {0}")]
InvalidBlockDevicePath(String),
/// A root block device was already added.
#[error("A root block device already exists!")]
RootBlockDeviceAlreadyAdded,
}

impl Display for DriveError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
use self::DriveError::*;
match self {
CreateBlockDevice(err) => write!(f, "Unable to create the block device: {err:?}"),
CreateRateLimiter(err) => write!(f, "Cannot create RateLimiter: {err}"),
DeviceUpdate(err) => write!(f, "Unable to patch the block device: {err}"),
InvalidBlockDevicePath(path) => write!(f, "Invalid block device path: {path}"),
RootBlockDeviceAlreadyAdded => write!(f, "A root block device already exists!"),
}
}
}
type Result<T> = result::Result<T, DriveError>;

/// Use this structure to set up the Block Device before booting the kernel.
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
Expand Down

0 comments on commit af3207c

Please sign in to comment.