xenstore/
error.rs

1use std::ffi::{FromVecWithNulError, IntoStringError, NulError};
2use std::io;
3use std::num::ParseIntError;
4use std::str::Utf8Error;
5use std::string::FromUtf8Error;
6
7use tokio::sync::mpsc::error::{SendError, TrySendError};
8use tokio::sync::oneshot::error::RecvError;
9
10use crate::bus::XsdMessage;
11
12#[derive(thiserror::Error, Debug)]
13pub enum Error {
14    #[error("io issue encountered: {0}")]
15    Io(#[from] io::Error),
16    #[error("invalid data received on bus")]
17    InvalidBusData,
18    #[error("utf8 string decode failed: {0}")]
19    Utf8DecodeString(#[from] FromUtf8Error),
20    #[error("utf8 str decode failed: {0}")]
21    Utf8DecodeStr(#[from] Utf8Error),
22    #[error("unable to decode cstring as utf8: {0}")]
23    Utf8DecodeCstring(#[from] IntoStringError),
24    #[error("nul byte found in string: {0}")]
25    NulByteFoundString(#[from] NulError),
26    #[error("unable to find nul byte in vec: {0}")]
27    VecNulByteNotFound(#[from] FromVecWithNulError),
28    #[error("unable to parse integer: {0}")]
29    ParseInt(#[from] ParseIntError),
30    #[error("bus was not found on any available path")]
31    BusNotFound,
32    #[error("store responded with error: `{0}`")]
33    ResponseError(String),
34    #[error("invalid permissions provided")]
35    InvalidPermissions,
36    #[error("failed to receive reply: {0}")]
37    ReceiverError(#[from] RecvError),
38    #[error("failed to send request: {0}")]
39    SendError(#[from] SendError<XsdMessage>),
40    #[error("failed to send request: {0}")]
41    TrySendError(#[from] TrySendError<XsdMessage>),
42}
43
44impl Error {
45    pub fn is_noent_response(&self) -> bool {
46        match self {
47            Error::ResponseError(message) => message == "ENOENT",
48            _ => false,
49        }
50    }
51
52    pub fn is_again_response(&self) -> bool {
53        match self {
54            Error::ResponseError(message) => message == "EAGAIN",
55            _ => false,
56        }
57    }
58}
59
60pub type Result<T> = std::result::Result<T, Error>;