Skip to main content

which/
error.rs

1use std::{fmt, io};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Copy, Clone, Eq, PartialEq, Debug)]
6pub enum Error {
7    /// An executable binary with that name was not found
8    CannotFindBinaryPath,
9    /// There was nowhere to search and the provided name wasn't an absolute path
10    CannotGetCurrentDirAndPathListEmpty,
11    /// Failed to canonicalize the path found
12    CannotCanonicalize,
13}
14
15impl std::error::Error for Error {}
16
17impl fmt::Display for Error {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Error::CannotFindBinaryPath => write!(f, "cannot find binary path"),
21            Error::CannotGetCurrentDirAndPathListEmpty => write!(
22                f,
23                "no path to search and provided name is not an absolute path"
24            ),
25            Error::CannotCanonicalize => write!(f, "cannot canonicalize path"),
26        }
27    }
28}
29
30#[derive(Debug)]
31#[non_exhaustive]
32pub enum NonFatalError {
33    Io(io::Error),
34    /// The Windows PATHEXT environment variable was not populated with any usable extensions,
35    /// and the query did not specify a file extension. This is technically legal but probably not
36    /// intentional.
37    PathExtNotPopulated,
38}
39
40impl std::error::Error for NonFatalError {}
41
42impl fmt::Display for NonFatalError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Self::Io(e) => write!(f, "{e}"),
46            Self::PathExtNotPopulated => write!(f, "PATHEXT environment variable is not populated, and the query did not specify a file extension"),
47        }
48    }
49}