easyfix_dictionary/dictionary/error.rs
1use std::io;
2
3use quick_xml::de;
4
5use crate::xml::{BasicType, MsgCat, MsgType};
6
7/// Errors that can occur during dictionary operations.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 /// Input/output error during file operations
11 #[error("IO error: {0}")]
12 Io(#[from] io::Error),
13
14 /// XML parsing error when reading dictionary files
15 #[error("XML parsing error: {0}")]
16 XmlParse(#[from] de::DeError),
17
18 /// Dictionary validation failed
19 #[error("Validation error: {0}")]
20 Validation(#[from] ValidationError),
21
22 /// Dictionary builder configuration error
23 #[error("Builder error: {0}")]
24 Builder(#[from] BuilderError),
25}
26
27/// Errors related to dictionary structure and content validation.
28///
29/// These errors indicate problems with the dictionary's structure, such as
30/// missing references, duplicates, or invalid relationships between elements.
31#[derive(Debug, thiserror::Error)]
32pub enum ValidationError {
33 /// Referenced field was not found in the dictionary
34 #[error("Unknown field {0}")]
35 UnknownField(String),
36
37 /// Referenced component was not found in the dictionary
38 #[error("Unknown component {0}")]
39 UnknownComponent(String),
40
41 /// A field with the same name already exists in the dictionary
42 #[error("Duplicated field {0}")]
43 DuplicatedField(String),
44
45 /// A component with the same name already exists in the dictionary
46 #[error("Duplicated component {0}")]
47 DuplicatedComponent(String),
48
49 /// A group with the same name already exists in the dictionary
50 #[error("Duplicated group {0}")]
51 DuplicatedGroup(String),
52
53 /// A message with the same name already exists in the dictionary
54 #[error("Duplicated message name {0}")]
55 DuplicatedMessageName(String),
56
57 /// A message with the same type already exists in the dictionary
58 #[error("Duplicated message type {0}")]
59 DuplicatedMessageType(MsgType),
60
61 /// Component or group has no members defined
62 #[error("Component/group {0} has no members")]
63 EmptyContainer(String),
64
65 /// Message has no fields or components defined
66 #[error("Message {0} has no members")]
67 EmptyMessage(String),
68
69 /// Message has an unexpected category for this dictionary type
70 #[error("Unexpected message category {0:?} ({1})")]
71 UnexpectedMessageCategory(MsgCat, String),
72
73 /// Field was defined in the dictionary but not used in any message, component, or group
74 ///
75 /// This error only occurs when strict validation is enabled with `with_strict_check(true)`.
76 #[error("Unused field {0}({1})")]
77 UnusedField(String, u16),
78
79 /// Component was defined in the dictionary but not used in any message or other component
80 ///
81 /// This error only occurs when strict validation is enabled with `with_strict_check(true)`.
82 #[error("Unused component {0}")]
83 UnusedComponent(String),
84
85 /// A field the standard header/trailer must carry is not defined there
86 ///
87 /// This error only occurs when strict validation is enabled with `with_strict_check(true)`.
88 #[error("Missing required field {0}({1})")]
89 MissingRequiredField(String, u16),
90
91 /// A field the standard header/trailer must carry is declared optional
92 ///
93 /// This error only occurs when strict validation is enabled with `with_strict_check(true)`.
94 #[error("Required field {0}({1}) is marked optional")]
95 OptionalRequiredField(String, u16),
96
97 /// A required standard field in the header/trailer has incorrect properties
98 ///
99 /// This error occurs when a required FIX field (like BeginString or BodyLength)
100 /// is defined with the wrong tag number or data type, or - for the fields
101 /// whose position is mandated - does not sit where it must.
102 /// This error only occurs when strict validation is enabled with `with_strict_check(true)`.
103 #[error("Invalid required field {0}({1}) [{2:?}]")]
104 InvalidRequiredField(String, u16, BasicType),
105
106 /// A circular dependency was detected in component or group references
107 ///
108 /// This error occurs when components or groups reference each other in a way that
109 /// creates an infinite loop. For example, if Component A contains Component B, and
110 /// Component B contains Component A, this would create a circular reference.
111 #[error("Circular reference found: {0}")]
112 CircularReference(String),
113}
114
115/// Errors related to dictionary builder configuration.
116///
117/// These errors indicate problems with how the dictionary builder is being used,
118/// such as missing required configuration or incompatible version combinations.
119#[derive(Debug, thiserror::Error)]
120pub enum BuilderError {
121 /// FIX version not recognized or supported
122 #[error("Unknown version {0}")]
123 UnknownVersion(String),
124
125 /// No dictionary was specified in the builder
126 #[error("No dictionary specified")]
127 Unspecified,
128
129 /// Incompatible FIX version combinations
130 #[error("Incompatible version combination")]
131 IncompatibleVersion,
132}