ofx_rs/aggregates/
error.rs1use core::fmt;
2
3#[non_exhaustive]
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum AggregateError {
7 MissingRequiredField {
9 aggregate: String,
10 field: &'static str,
11 },
12 MutuallyExclusiveFields {
14 aggregate: String,
15 field_a: &'static str,
16 field_b: &'static str,
17 },
18 InvalidFieldValue {
20 aggregate: String,
21 field: &'static str,
22 value: String,
23 reason: String,
24 },
25}
26
27impl fmt::Display for AggregateError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::MissingRequiredField { aggregate, field } => {
31 write!(f, "missing required field '{field}' in <{aggregate}>")
32 }
33 Self::MutuallyExclusiveFields {
34 aggregate,
35 field_a,
36 field_b,
37 } => {
38 write!(
39 f,
40 "mutually exclusive fields '{field_a}' and '{field_b}' both present in <{aggregate}>"
41 )
42 }
43 Self::InvalidFieldValue {
44 aggregate,
45 field,
46 value,
47 reason,
48 } => {
49 write!(
50 f,
51 "invalid value '{value}' for field '{field}' in <{aggregate}>: {reason}"
52 )
53 }
54 }
55 }
56}
57
58impl std::error::Error for AggregateError {}