1use serde_json;
2use std::fmt;
3use std::io; #[derive(Debug, Clone)]
6pub enum BenfError {
7 InvalidInput(String),
8 NetworkError(String),
9 FileError(String),
10 ParseError(String),
11 NoNumbersFound,
12 InsufficientData(usize),
13 IoError(String), SerializationError(String), }
16
17impl fmt::Display for BenfError {
18 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19 match self {
20 BenfError::InvalidInput(msg) => write!(f, "Invalid input: {msg}"),
21 BenfError::NetworkError(msg) => write!(f, "Network error: {msg}"),
22 BenfError::FileError(msg) => write!(f, "File error: {msg}"),
23 BenfError::ParseError(msg) => write!(f, "Parse error: {msg}"),
24 BenfError::NoNumbersFound => write!(f, "No numbers found in input"),
25 BenfError::InsufficientData(count) => {
26 write!(
27 f,
28 "Insufficient data for analysis: {count} numbers (minimum 30 recommended)"
29 )
30 }
31 BenfError::IoError(msg) => write!(f, "I/O error: {msg}"),
32 BenfError::SerializationError(msg) => write!(f, "Serialization error: {msg}"),
33 }
34 }
35}
36
37impl std::error::Error for BenfError {}
38
39pub type Result<T> = std::result::Result<T, BenfError>;
40
41pub type LawkitError = BenfError;
43
44impl From<io::Error> for BenfError {
45 fn from(err: io::Error) -> Self {
46 BenfError::IoError(err.to_string())
47 }
48}
49
50impl From<serde_json::Error> for BenfError {
51 fn from(err: serde_json::Error) -> Self {
52 BenfError::SerializationError(err.to_string())
53 }
54}