1use chrono::Duration;
2
3use crate::OfficeError;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub enum ErrorCode {
7 System(SystemErrorCode),
9 Parse(ParseErrorCode),
11 Format(FormatErrorCode),
13 Document(DocumentErrorCode),
15 Common(CommonErrorCode),
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum SystemErrorCode {
22 NotFound = 1001, PermissionDenied = 1002, Corrupted = 1003, IoError = 1100, ZipError = 1101, NetworkError = 1102, }
32
33#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35pub enum ParseErrorCode {
36 Xml = 2001, Json = 2002, Encoding = 2003, MissingElement = 2101, InvalidAttribute = 2102, InvalidNamespace = 2103, UnsupportedVersion = 2104, }
47
48#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub enum FormatErrorCode {
51 InvalidFormat = 3001, UnsupportedFormat = 3002, VersionMismatch = 3003, InvalidReference = 3101, InvalidValue = 3102, OutOfRange = 3103, }
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64pub enum DocumentErrorCode {
65 XlsxWorksheetNotFound = 4001, XlsxInvalidCellReference = 4002, XlsxInvalidFormula = 4003, XlsxInvalidStyle = 4004, DocxStyleNotFound = 5001, DocxInvalidTableStructure = 5002, DocxInvalidParagraph = 5003, DocxBookmarkNotFound = 5004, PptxInvalidPresentation = 6001, PptxInvalidSlide = 6002, PptxInvalidShape = 6003, PptxInvalidText = 6004, }
83
84#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86pub enum CommonErrorCode {
87 UnknownError = 9001, NotImplemented = 9002, InvalidOperation = 9003, Timeout = 9004, }
93
94#[derive(Debug, Clone)]
96pub struct RecoverySuggestion {
97 pub message: String,
98 pub action: RecoveryAction,
99}
100
101#[derive(Debug, Clone)]
103pub enum RecoveryAction {
104 Retry(u32),
106 UseDefault,
108 Fallback(String),
110 SkipElement,
112 UserInput(String),
114 Ignore,
116 None,
118}
119
120pub struct RecoveryStrategy {
122 pub pattern: ErrorPattern, pub operation: RecoveryAction, pub max_attempts: u32, pub backoff: Duration, }
127
128pub enum ErrorPattern {
130 ContinuousFailure(u32), PeriodicError(String), BurstError { threshold: u32,
134 time_window: Duration,
135 },
136}