Skip to main content

mago_php_version/
error.rs

1use std::error::Error;
2use std::num::ParseIntError;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum ParsingError {
7    InvalidFormat,
8    ParseIntError(ParseIntError),
9}
10
11impl std::fmt::Display for ParsingError {
12    #[inline]
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        match self {
15            Self::InvalidFormat => write!(f, "Invalid version format, expected 'major.minor.patch'."),
16            Self::ParseIntError(e) => write!(f, "Failed to parse integer component of version: {e}."),
17        }
18    }
19}
20
21impl Error for ParsingError {
22    #[inline]
23    fn source(&self) -> Option<&(dyn Error + 'static)> {
24        match self {
25            Self::ParseIntError(e) => Some(e),
26            Self::InvalidFormat => None,
27        }
28    }
29}
30
31impl From<ParseIntError> for ParsingError {
32    #[inline]
33    fn from(e: ParseIntError) -> Self {
34        Self::ParseIntError(e)
35    }
36}