1use hotfix_dictionary::TagU32;
2use std::collections::HashSet;
3use std::io;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum EncodingError {
8 #[error("IO error")]
9 IOError(#[from] io::Error),
10}
11
12pub type EncodingResult<T> = Result<T, EncodingError>;
13
14#[derive(Error, Debug)]
15pub enum ParserError {
16 #[error("IO error")]
17 IOError(#[from] io::Error),
18 #[error("field (tag = {0}) is missing from FIX dictionary")]
19 InvalidField(u32),
20 #[error("group (tag = {0}) is missing from FIX dictionary")]
21 InvalidGroup(u32),
22 #[error(
23 "field (tag = {tag}) is not in a valid position within the group (group tag = {group_tag})"
24 )]
25 InvalidGroupFieldOrder { tag: u32, group_tag: u32 },
26 #[error("component (name = {0}) is missing from FIX dictionary")]
27 InvalidComponent(String),
28 #[error("MsgType {0} is not a valid message type")]
29 InvalidMsgType(String),
30 #[error(
31 "required field (tag = {tag}) is missing{}",
32 match group_tag { Some(g) => format!(" from repeating group (group tag = {g})"), None => String::new() }
33 )]
34 RequiredFieldMissing { tag: u32, group_tag: Option<u32> },
35 #[error("malformed message: {0}")]
36 Malformed(String),
37}
38
39pub type ParserResult<T> = Result<T, ParserError>;
40
41#[derive(Error, Debug)]
42#[allow(clippy::enum_variant_names)]
43pub(crate) enum MessageIntegrityError {
44 #[error("Invalid BeginString")]
45 InvalidBeginString,
46 #[error("Invalid BodyLength")]
47 InvalidBodyLength,
48 #[error("Invalid MsgType")]
49 InvalidMsgType,
50 #[error("Invalid CheckSum")]
51 InvalidCheckSum,
52}
53
54#[derive(Error, Debug)]
55pub enum SetGroupsError {
56 #[error("Supplied empty vector of groups")]
57 EmptyGroups,
58 #[error("Supplied groups contain multiple start tags")]
59 MultipleStartTagsAndDelimiters(HashSet<(TagU32, TagU32)>),
60}