1use alloc::boxed::Box;
2
3use crate::io;
4
5#[derive(thiserror::Error, Debug)]
6pub enum VsockError {
7 #[error("operation not supported")]
8 NotSupported,
9 #[error("operation should be retried")]
10 Retry,
11 #[error("connection not found")]
12 NotConnected,
13 #[error("connection already exists")]
14 AlreadyExists,
15 #[error("device is not available")]
16 NotAvailable,
17 #[error("other error: {0}")]
18 Other(Box<dyn core::error::Error>),
19}
20
21impl From<VsockError> for io::ErrorKind {
22 fn from(value: VsockError) -> Self {
23 match value {
24 VsockError::NotSupported => io::ErrorKind::Unsupported,
25 VsockError::Retry => io::ErrorKind::Interrupted,
26 VsockError::NotConnected => io::ErrorKind::BrokenPipe,
27 VsockError::AlreadyExists => io::ErrorKind::NotAvailable,
28 VsockError::NotAvailable => io::ErrorKind::NotAvailable,
29 VsockError::Other(error) => io::ErrorKind::Other(error),
30 }
31 }
32}