Skip to main content

ofx_rs/header/
error.rs

1use core::fmt;
2
3/// Error returned when parsing an OFX header.
4#[non_exhaustive]
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum HeaderError {
7    /// No OFX header was found in the input.
8    Missing,
9    /// The OFX processing instruction was malformed.
10    MalformedProcessingInstruction { detail: String },
11    /// A required attribute was missing from the header.
12    MissingAttribute { attribute: &'static str },
13    /// The VERSION attribute had an invalid value.
14    InvalidVersion { value: String },
15    /// The SECURITY attribute had an invalid value.
16    InvalidSecurity { value: String },
17}
18
19impl fmt::Display for HeaderError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::Missing => f.write_str("no OFX header found"),
23            Self::MalformedProcessingInstruction { detail } => {
24                write!(f, "malformed OFX processing instruction: {detail}")
25            }
26            Self::MissingAttribute { attribute } => {
27                write!(f, "missing required OFX header attribute: {attribute}")
28            }
29            Self::InvalidVersion { value } => {
30                write!(f, "invalid OFX version in header: '{value}'")
31            }
32            Self::InvalidSecurity { value } => {
33                write!(f, "invalid OFX security level in header: '{value}'")
34            }
35        }
36    }
37}
38
39impl std::error::Error for HeaderError {}