| 1 | use crate::Key; |
| 2 | use std::fmt::{Display, Formatter}; |
| 3 | |
| 4 | /// # Error |
| 5 | /// |
| 6 | /// This Enum currently contains two variants, MissingArgs and Other. |
| 7 | /// |
| 8 | /// ## MissingArgs(Key) |
| 9 | /// |
| 10 | /// This variant is used internally by Jargon to warn when a required argument |
| 11 | /// (from the `res_*` functions) does not exist. |
| 12 | /// |
| 13 | /// ## Other(String) |
| 14 | /// |
| 15 | /// This variant is used internally by Jargon when converting other types of errors to itself. |
| 16 | /// *STD ERROR TYPES ARE NOT YET IMPLEMENTED IN TRAITS* |
| 17 | #[derive(Debug, Eq, PartialEq)] |
| 18 | pub enum Error { |
| 19 | /// # MissingArgs(Key) |
| 20 | /// |
| 21 | /// This variant is used internally by Jargon to warn when a required argument |
| 22 | /// (from the `res_*` functions) does not exist. |
| 23 | MissingArg(Key), |
| 24 | |
| 25 | /// # Other(String) |
| 26 | /// |
| 27 | /// This variant is used internally by Jargon when converting other types of errors to itself. |
| 28 | /// *STD ERROR TYPES ARE NOT YET IMPLEMENTED IN TRAITS* |
| 29 | Other(String), |
| 30 | } |
| 31 | |
| 32 | impl std::error::Error for Error {} |
| 33 | |
| 34 | impl Display for Error { |
| 35 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 36 | write!( |
| 37 | f, |
| 38 | "{}", |
| 39 | match self { |
| 40 | Error::MissingArg(k) => format!("Missing argument: '{}'", k), |
| 41 | Error::Other(e) => e.to_string(), |
| 42 | } |
| 43 | ) |
| 44 | } |
| 45 | } |