Skip to main content

ferrous_opencc/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum OpenCCError {
5    /// I/O error
6    #[error("I/O error: {0}")]
7    Io(#[from] std::io::Error),
8
9    /// Error parsing JSON configuration file
10    #[error("JSON parsing error: {0}")]
11    Json(#[from] serde_json::Error),
12
13    /// Error related to FST library
14    #[error("FST error: {0}")]
15    Fst(#[from] fst::Error),
16
17    /// Invalid rkyv dictionary format
18    #[error("Invalid rkyv dictionary format: {0}")]
19    InvalidDictFormat(#[from] rkyv::rancor::Error),
20
21    /// Invalid configuration format
22    #[error("Invalid configuration format: {0}")]
23    InvalidConfig(String),
24
25    /// Configuration or dictionary not found in embedded resources
26    #[error("Configuration or resource not found in embedded data: {0}")]
27    ConfigNotFound(String),
28
29    /// Required file not found
30    #[error("File not found: {0}")]
31    FileNotFound(String),
32
33    /// Unsupported dictionary type
34    #[error("Unsupported dictionary type: {0}")]
35    UnsupportedDictType(String),
36
37    /// Error compiling dictionary from text file
38    #[error("Dictionary compile failed")]
39    DictCompileError(#[from] anyhow::Error),
40}
41
42pub type Result<T> = std::result::Result<T, OpenCCError>;