use remain::sorted;
use thiserror::Error as ThisError;
use vm_memory::GuestMemoryError;
use vmm_vhost::message::VhostUserProtocolFeatures;
use vmm_vhost::Error as VhostError;
#[sorted]
#[derive(ThisError, Debug)]
pub enum Error {
#[error("failed to copy config to a buffer: {0}")]
CopyConfig(std::io::Error),
#[error("could not create backend req handler: {0}")]
CreateBackendReqHandler(VhostError),
#[error("failed to create Event: {0}")]
CreateEvent(base::Error),
#[error("failed to get config: {0}")]
GetConfig(VhostError),
#[error("failed to get features: {0}")]
GetFeatures(VhostError),
#[error("failed to get host address: {0}")]
GetHostAddress(GuestMemoryError),
#[error("failed to get protocol features: {0}")]
GetProtocolFeatures(VhostError),
#[error("failed to get number of queues: {0}")]
GetQueueNum(VhostError),
#[error("failed to get vring base offset: {0}")]
GetVringBase(VhostError),
#[error("MSI-X config is unavailable")]
MsixConfigUnavailable,
#[error("MSI-X irqfd is unavailable")]
MsixIrqfdUnavailable,
#[error("protocol feature is not negotiated: {0:?}")]
ProtocolFeatureNotNegoiated(VhostUserProtocolFeatures),
#[error("failed to reset owner: {0}")]
ResetOwner(VhostError),
#[error("failed to restore: {0}")]
Restore(VhostError),
#[error("failed to convert a serde Value to slice {0}")]
SerdeValueToSlice(serde_json::Error),
#[error("failed to set config: {0}")]
SetConfig(VhostError),
#[error("failed to set device request channel: {0}")]
SetDeviceRequestChannel(VhostError),
#[error("failed to set features: {0}")]
SetFeatures(VhostError),
#[error("failed to set memory map regions: {0}")]
SetMemTable(VhostError),
#[error("failed to set owner: {0}")]
SetOwner(VhostError),
#[error("failed to set protocol features: {0}")]
SetProtocolFeatures(VhostError),
#[error("failed to set vring address: {0}")]
SetVringAddr(VhostError),
#[error("failed to set vring base offset: {0}")]
SetVringBase(VhostError),
#[error("failed to set eventfd to signal used vring buffers: {0}")]
SetVringCall(VhostError),
#[error("failed to enable or disable vring: {0}")]
SetVringEnable(VhostError),
#[error("failed to set eventfd for adding buffers to vring: {0}")]
SetVringKick(VhostError),
#[error("failed to set the size of the queue: {0}")]
SetVringNum(VhostError),
#[error("failed to enumerate shmem regions {0}")]
ShmemRegions(VhostError),
#[error("failed to sleep the device {0}")]
Sleep(VhostError),
#[error("Failed to convert a slice to a serde Value: {0}")]
SliceToSerdeValue(serde_json::Error),
#[error("failed to snapshot: {0}")]
Snapshot(VhostError),
#[error("failed to connect socket: {0}")]
SocketConnect(std::io::Error),
#[error("failed to spawn worker: {0}")]
SpawnWorker(std::io::Error),
#[error("tag is too long: {len} > {max}")]
TagTooLong { len: usize, max: usize },
#[error("too many shmem regions: {0} > 1")]
TooManyShmemRegions(usize),
#[error("vring base returned by vhost-user backend is too big: {0}")]
VringBaseTooBig(u32),
#[error("failed to wake the vhost user device.")]
Wake(VhostError),
#[error("failed to wake the worker.")]
WakeWorker,
}
pub type Result<T> = std::result::Result<T, Error>;