qrexec_binds/
errors.rs

1use std::{
2    error::Error,
3    fmt::{
4        Display,
5        Formatter,
6        self,
7    },
8    io,
9};
10use anyhow;
11
12pub type QRXRes<T> = Result<T, QRXErr>;
13
14// ERROR Messages :  
15pub(crate) const STDOUT_ERR: &str = 
16    "Error: child proc failed to produce stdout";
17pub(crate) const STDIN_ERR: &str = 
18    "Error: child proc failed to produce stdin";
19pub(crate) const STDERR_ERR: &str =
20    "Error: child proc failed to produce stderr";
21
22
23#[derive(Debug)]
24pub enum QRXErr {
25    Io(io::Error), 
26    Anyhow(anyhow::Error), 
27}
28
29impl Error for QRXErr {}
30
31impl Display for QRXErr {
32    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
33        match self {
34            Self::Io(io_err) => write!(f, "{}", io_err),
35            Self::Anyhow(ah_err) => write!(f, "{}", ah_err), 
36        }  
37    }
38}
39
40impl From<anyhow::Error> for QRXErr {
41    fn from(err: anyhow::Error) -> Self {
42        return Self::Anyhow(err);
43    }
44}
45
46impl From<io::Error> for QRXErr {
47    fn from(err: io::Error) -> Self {
48        return Self::Io(err);
49    }
50}