nagisa_render/error.rs
1//! 引擎错误类型。`render_*` 返回 `Result`,调用方决定回退(如改发纯文字)。
2
3use thiserror::Error;
4
5/// 排版引擎错误。
6#[derive(Debug, Error)]
7pub enum Error {
8 /// 字体栈为空 / 字体数据损坏。
9 #[error("字体加载失败:{0}")]
10 FontLoad(String),
11 /// 标记语言语法错误。
12 #[error("标记解析错误(第 {line} 行):{msg}")]
13 Parse {
14 /// 出错的行号(从 1 起)。
15 line: usize,
16 /// 错误说明。
17 msg: String,
18 },
19 /// 内嵌图片解码失败 / `@名字` 未提供。
20 #[error("图片错误:{0}")]
21 Image(String),
22 /// 图片编码失败。
23 #[error("图片编码失败:{0}")]
24 Encode(String),
25 /// 版式异常(如宽度 ≤ 0、画布尺寸非法)。
26 #[error("版式错误:{0}")]
27 Layout(String),
28}
29
30/// 引擎内部用的 `Result` 别名。
31pub type Result<T> = std::result::Result<T, Error>;