code_executor/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("Compilation error: {message}")]
    Compilation { message: String },
    #[error("IO error: {0}")] 
    IO(#[from] std::io::Error),
}

impl From<std::string::FromUtf8Error> for Error {
    fn from(error: std::string::FromUtf8Error) -> Self {
        Error::IO(std::io::Error::other(error))
    }
}

impl From<nix::errno::Errno> for Error {
    fn from(value: nix::errno::Errno) -> Self {
        Self::IO(std::io::Error::from(value))
    }
}

impl From<libseccomp::error::SeccompError> for Error {
    fn from(value: libseccomp::error::SeccompError) -> Self {
        Self::IO(std::io::Error::other(value.to_string()))
    }
}