| 1 | use std::{fmt, io};
|
| 2 |
|
| 3 | pub type Result<T> = std::result::Result<T, Error>;
|
| 4 |
|
| 5 | #[derive (Copy, Clone, Eq, PartialEq, Debug)]
|
| 6 | pub 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 |
|
| 15 | impl std::error::Error for Error {}
|
| 16 |
|
| 17 | impl 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 ]
|
| 32 | pub enum NonFatalError {
|
| 33 | Io(io::Error),
|
| 34 | }
|
| 35 |
|
| 36 | impl std::error::Error for NonFatalError {}
|
| 37 |
|
| 38 | impl fmt::Display for NonFatalError {
|
| 39 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 40 | match self {
|
| 41 | Self::Io(e: &Error) => write!(f, " {e}" ),
|
| 42 | }
|
| 43 | }
|
| 44 | }
|
| 45 | |