Skip to main content

ofd_core/
error.rs

1//! 错误类型定义。
2
3use thiserror::Error;
4
5/// 解析 OFD 文档过程中可能出现的错误。
6#[derive(Debug, Error)]
7pub enum OfdError {
8    /// 底层 IO 错误。
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// ZIP 容器读取错误(见第 6 章 容器方案)。
13    #[error("zip container error: {0}")]
14    Zip(#[from] zip::result::ZipError),
15
16    /// XML 反序列化错误。
17    #[error("xml parse error: {0}")]
18    Xml(#[from] quick_xml::DeError),
19
20    /// 基础数据类型解析失败(见 7.3)。
21    #[error("invalid {ty} value {value:?}: {reason}")]
22    BasicType {
23        /// 数据类型名称,如 `ST_Box`。
24        ty: &'static str,
25        /// 原始字符串值。
26        value: String,
27        /// 失败原因。
28        reason: String,
29    },
30
31    /// 包内缺少必需的文件。
32    #[error("entry not found in package: {0}")]
33    EntryNotFound(String),
34
35    /// 文档结构不符合规范要求。
36    #[error("invalid OFD structure: {0}")]
37    Structure(String),
38
39    /// 图片编解码错误(见 [`crate::render`])。
40    #[error("image codec error: {0}")]
41    Image(#[from] image::ImageError),
42
43    /// 渲染过程中的错误(见 [`crate::render`])。
44    #[error("render error: {0}")]
45    Render(String),
46}
47
48/// 本 crate 的统一 `Result` 别名。
49pub type Result<T> = std::result::Result<T, OfdError>;