dm_database_parser_sqllog/
error.rs

1//! 错误类型定义
2//!
3//! 定义了解析过程中可能出现的所有错误类型。
4
5use thiserror::Error;
6
7/// 解析错误类型
8///
9/// 包含了 SQL 日志解析过程中可能遇到的所有错误情况。
10#[derive(Debug, Clone, PartialEq, Error)]
11pub enum ParseError {
12    /// 通用的格式错误
13    #[error("invalid format")]
14    InvalidFormat,
15
16    /// 文件未找到或无法访问
17    #[error("file not found or inaccessible: {0}")]
18    FileNotFound(String),
19
20    /// 输入为空
21    #[error("empty input: no lines provided")]
22    EmptyInput,
23
24    /// 无效的记录起始行
25    #[error("invalid record start line: line does not match expected format")]
26    InvalidRecordStartLine,
27
28    /// 行长度不足
29    #[error("line too short: expected at least 25 characters, got {0}")]
30    LineTooShort(usize),
31
32    /// Meta 部分缺少右括号
33    #[error("missing closing parenthesis in meta section")]
34    MissingClosingParen,
35
36    /// Meta 字段数量不足
37    #[error("insufficient meta fields: expected at least 7 fields, got {0}")]
38    InsufficientMetaFields(usize),
39
40    /// EP 字段格式错误
41    #[error("invalid EP format: expected 'EP[number]', got '{0}'")]
42    InvalidEpFormat(String),
43
44    /// EP 数字解析失败
45    #[error("failed to parse EP number: {0}")]
46    EpParseError(String),
47
48    /// 字段格式不匹配
49    #[error("invalid field format: expected '{expected}', got '{actual}'")]
50    InvalidFieldFormat {
51        /// 期望的前缀
52        expected: String,
53        /// 实际的字段内容
54        actual: String,
55    },
56
57    /// 整数解析失败
58    #[error("failed to parse {field} as integer: {value}")]
59    IntParseError {
60        /// 字段名
61        field: String,
62        /// 字段值
63        value: String,
64    },
65
66    /// Indicators 解析失败
67    #[error("failed to parse indicators: {0}")]
68    IndicatorsParseError(String),
69}