which/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{fmt, io};

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Error {
    /// An executable binary with that name was not found
    CannotFindBinaryPath,
    /// There was nowhere to search and the provided name wasn't an absolute path
    CannotGetCurrentDirAndPathListEmpty,
    /// Failed to canonicalize the path found
    CannotCanonicalize,
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::CannotFindBinaryPath => write!(f, "cannot find binary path"),
            Error::CannotGetCurrentDirAndPathListEmpty => write!(
                f,
                "no path to search and provided name is not an absolute path"
            ),
            Error::CannotCanonicalize => write!(f, "cannot canonicalize path"),
        }
    }
}

#[derive(Debug)]
#[non_exhaustive]
pub enum NonFatalError {
    Io(io::Error),
}

impl std::error::Error for NonFatalError {}

impl fmt::Display for NonFatalError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Io(e) => write!(f, "{e}"),
        }
    }
}