Skip to main content

utopia_detector/
error.rs

1//! The error type of the detectors.
2
3/// Why a detector refused an argument.
4///
5/// PHP: one variant per PHP exception class (see [`Error::php_class`]).
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7pub enum Error {
8    /// An input kind the framework detector does not read, such as
9    /// `language`.
10    ///
11    /// PHP: `\InvalidArgumentException`.
12    #[error("{0}")]
13    InvalidArgument(String),
14    /// A strategy name other than `filematch`, `extension` and `languages`.
15    ///
16    /// PHP: `\Exception`.
17    #[error("{0}")]
18    Exception(String),
19}
20
21impl Error {
22    /// The name of the exception class this error matches, such as
23    /// `InvalidArgumentException`.
24    ///
25    /// PHP: the class of the exception `utopia-php/detector` throws in the
26    /// same case.
27    pub fn php_class(&self) -> &'static str {
28        match self {
29            Error::InvalidArgument(_) => "InvalidArgumentException",
30            Error::Exception(_) => "Exception",
31        }
32    }
33}