formatparse_core/
error.rs1use std::fmt;
6
7#[derive(Debug, Clone)]
9pub enum FormatParseError {
10 PatternError(String),
12 RegexError(String),
14 ConversionError(String, String), RepeatedNameError(String),
18 CustomTypeError(String, String), RegexGroupIndexError(String, usize, i64), NotImplementedError(String),
24 MissingFieldError(String),
26}
27
28impl fmt::Display for FormatParseError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 FormatParseError::PatternError(msg) => write!(f, "Pattern error: {}", msg),
32 FormatParseError::RegexError(msg) => write!(f, "Invalid regex pattern: {}", msg),
33 FormatParseError::ConversionError(value, target_type) => {
34 write!(f, "Invalid {}: {}", target_type, value)
35 }
36 FormatParseError::RepeatedNameError(name) => {
37 write!(f, "Repeated name '{}' with mismatched types", name)
38 }
39 FormatParseError::CustomTypeError(type_name, msg) => {
40 write!(f, "Custom type '{}' error: {}", type_name, msg)
41 }
42 FormatParseError::RegexGroupIndexError(type_name, actual, expected) => {
43 write!(
44 f,
45 "Custom type '{}' pattern has {} capturing groups but regex_group_count is {}",
46 type_name, actual, expected
47 )
48 }
49 FormatParseError::NotImplementedError(feature) => {
50 write!(f, "{} is not supported", feature)
51 }
52 FormatParseError::MissingFieldError(field) => {
53 write!(f, "Missing required field: {}", field)
54 }
55 }
56 }
57}
58
59impl std::error::Error for FormatParseError {}