use io_uring_owner::{Owner, TakeError};
use core::fmt;
use core::fmt::Display;
use io_uring_opcode::OpError;
use slabbable::SlabbableError;
#[derive(Debug)]
pub enum UringBearerError {
IoUringCreate(String),
Duplicate,
SubmissionPush,
Submission(String),
Slab(String),
SlabBugSetGet(&'static str),
RegisterHandles(String),
Slabbable(SlabbableError),
InvalidParameterI32(&'static str, &'static str, i32),
BufferNoOwnership(usize),
BufferNotExist(usize),
BufferSelectedNotExist(u16),
BufferTake(TakeError),
BufferNotKernelOwned(usize),
FutexNoOwnership(usize),
FutexNotExist(usize),
FdNotRegistered(u32),
InvalidOwnership(Owner, usize),
FdRegisterFull,
FdRegisterFail,
Op(OpError),
}
impl Display for UringBearerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IoUringCreate(s) => write!(f, "IoUring Create: {}", s),
Self::Duplicate => write!(f, "The filehandle is already maped in. Possible duplicate?"),
Self::SubmissionPush => write!(f, "Submisionn push error. Is the squeue full?"),
Self::Submission(s) => write!(f, "Submission: {}", s),
Self::Slab(s) => write!(f, "Slab: {}", s),
Self::SlabBugSetGet(s) => write!(f, "Slab Bug: {}", s),
Self::RegisterHandles(s) => write!(f, "Register Handles: {}", s),
Self::Slabbable(e) => write!(f, "Slabbable: {}", e),
Self::InvalidParameterI32(at, s, val) => write!(
f,
"Invalid input parameter value {} at {} when {}",
val, at, s
),
Self::BufferNoOwnership(idx) => write!(f, "Buffer {} in invalid ownership state", idx),
Self::BufferNotExist(idx) => write!(f, "Buffer {} does not exist.", idx),
Self::BufferNotKernelOwned(idx) => {
write!(f, "Buffer {} is not owned by the kernel.", idx)
}
Self::BufferSelectedNotExist(sel_idx) => write!(
f,
"Selected {} does not exist within the given buffer.",
sel_idx
),
Self::BufferTake(take_err) => write!(f, "Unable to take buffer: {}", take_err),
Self::FutexNoOwnership(idx) => write!(f, "Futex {} in invalid ownership state", idx),
Self::FutexNotExist(idx) => write!(f, "Futex {} does not exist.", idx),
Self::FdNotRegistered(idx) => write!(f, "Fixed fd {} is not registered.", idx),
Self::InvalidOwnership(owner, idx) => {
write!(f, "Invalid current ownership {} of idx {}", owner, idx)
}
Self::FdRegisterFull => write!(
f,
"Map holding th registered filehandles is at capacity and cannot add more."
),
Self::FdRegisterFail => write!(f, "Failed to register filehandle."),
Self::Op(e) => write!(f, "OpCode: {}", e),
}
}
}
impl From<OpError> for UringBearerError {
fn from(e: OpError) -> UringBearerError {
UringBearerError::Op(e)
}
}
impl std::error::Error for UringBearerError {}