use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum FieldError {
#[error("field {tag}: value is not valid UTF-8")]
NotUtf8 {
tag: u32,
},
#[error("field {tag}: expected an integer, got {value:?}")]
NotInt {
tag: u32,
value: String,
},
#[error("field {tag}: expected a decimal, got {value:?}")]
NotDecimal {
tag: u32,
value: String,
},
#[error("field {tag}: expected a single character, got {value:?}")]
NotChar {
tag: u32,
value: String,
},
#[error("field {tag}: expected 'Y' or 'N', got {value:?}")]
NotBool {
tag: u32,
value: String,
},
#[error("field {tag}: invalid UTC timestamp {value:?}")]
NotTimestamp {
tag: u32,
value: String,
},
#[error("field {tag}: invalid UTC date-only {value:?}")]
NotDateOnly {
tag: u32,
value: String,
},
#[error("field {tag}: invalid UTC time-only {value:?}")]
NotTimeOnly {
tag: u32,
value: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum DecodeError {
#[error("empty input")]
Empty,
#[error("message does not begin with BeginString (tag 8)")]
MissingBeginString,
#[error("missing or invalid BodyLength (tag 9)")]
InvalidBodyLength,
#[error("declared BodyLength is 0")]
ZeroBodyLength,
#[error("declared BodyLength {declared} exceeds the maximum frame size {max}")]
BodyLengthTooLarge {
declared: usize,
max: usize,
},
#[error("repeating-group nesting exceeds the maximum depth {max}")]
GroupNestingTooDeep {
max: usize,
},
#[error("BodyLength mismatch: declared {declared}, actual {actual}")]
BodyLengthMismatch {
declared: usize,
actual: usize,
},
#[error("message does not carry MsgType (tag 35) as its third field")]
MissingMsgType,
#[error("missing or invalid CheckSum (tag 10)")]
MissingChecksum,
#[error("CheckSum mismatch: declared {declared:03}, computed {computed:03}")]
ChecksumMismatch {
declared: u32,
computed: u32,
},
#[error("garbled field near byte {offset}: {reason}")]
GarbledField {
offset: usize,
reason: &'static str,
},
#[error("truncated input near byte {offset}")]
Truncated {
offset: usize,
},
#[error("invalid tag number near byte {offset}")]
InvalidTag {
offset: usize,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[error("reject (reason {reason}, ref tag {ref_tag:?}): {text:?}")]
pub struct Reject {
pub reason: u32,
pub ref_tag: Option<u32>,
pub text: Option<String>,
pub session_status: Option<u16>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
#[error("do not send")]
pub struct DoNotSend;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[error("business reject (reason {reason}, ref tag {ref_tag:?}): {text:?}")]
pub struct BusinessReject {
pub reason: u32,
pub ref_tag: Option<u32>,
pub text: Option<String>,
}