1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// Crate errors enum
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Error {
	/// Error parsing string to [`Source`](crate::core::Source)
	SourceParse(String),

	/// Error parsing indicator parameter
	ParameterParse(String, String),

	/// Error parsing moving average
	MovingAverageParse,

	/// Invalid parameters for method creation
	WrongMethodParameters,

	/// Invalid indicator config error
	WrongConfig,

	/// Invalid candles error
	InvalidCandles,

	/// Any other error
	Other(String),
}

impl std::fmt::Display for Error {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			Self::SourceParse(value) => write!(f, "Unable to parse value as Source: {value:?}"),
			Self::ParameterParse(name, value) => {
				write!(f, "Unable to parse into {name}: {value:?}")
			}
			Self::WrongMethodParameters => write!(f, "Wrong method parameters"),
			Self::WrongConfig => write!(f, "Wrong config"),
			Self::InvalidCandles => write!(f, "Invalid candles"),
			Self::Other(reason) => f.write_str(reason),
			Self::MovingAverageParse => write!(f, "Error parsing moving average type and length"),
		}
	}
}

impl std::error::Error for Error {
	fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
		None
	}
}