Skip to main content

audio_cpp/
error.rs

1//! 统一错误类型。
2
3use std::path::PathBuf;
4
5/// audio-cpp 高层 API 的错误类型。
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// C ABI 调用失败(返回非 0),`msg` 为 shim 的 `audiocpp_last_error()`。
9    #[error("C ABI 调用失败: {0}")]
10    Ffi(String),
11
12    /// C++ 侧返回空句柄(如加载模型 / 创建会话失败),`msg` 为错误信息。
13    #[error("空句柄: {0}")]
14    NullHandle(String),
15
16    /// JSON 解析 / 序列化错误。
17    #[error("JSON 错误: {0}")]
18    Json(#[from] serde_json::Error),
19
20    /// 字符串或路径中含 NUL 字节,无法转为 C 字符串。
21    #[error("参数含 NUL 字节: {0}")]
22    Nul(#[from] std::ffi::NulError),
23
24    /// 路径含非法 UTF-8(capi.h 约定所有字符串均为 UTF-8)。
25    #[error("路径不是合法 UTF-8: {0}")]
26    NonUtf8Path(PathBuf),
27
28    /// 其他运行时错误(如示例中用户自选解码库的失败信息)。
29    #[error("{0}")]
30    Other(String),
31}