Skip to main content

three_dcf_core/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum DcfError {
7    #[error("io error: {0}")]
8    Io(#[from] std::io::Error),
9    #[error("serde json error: {0}")]
10    SerdeJson(#[from] serde_json::Error),
11    #[error("prost encode error: {0}")]
12    ProtoEncode(#[from] prost::EncodeError),
13    #[error("prost decode error: {0}")]
14    ProtoDecode(#[from] prost::DecodeError),
15    #[error("pdf support not enabled: {0:?}")]
16    PdfSupportDisabled(PathBuf),
17    #[error("ocr support not enabled")]
18    OcrSupportDisabled,
19    #[error("unsupported input format: {0:?}")]
20    UnsupportedInput(PathBuf),
21    #[error("invalid document: {0}")]
22    InvalidDocument(&'static str),
23    #[error("unknown preset: {0}")]
24    UnknownPreset(String),
25    #[error("tokenizer error: {0}")]
26    Tokenizer(String),
27    #[error("benchmark error: {0}")]
28    Bench(String),
29    #[error("other: {0}")]
30    Other(String),
31}
32
33pub type Result<T> = std::result::Result<T, DcfError>;
34
35impl From<anyhow::Error> for DcfError {
36    fn from(value: anyhow::Error) -> Self {
37        Self::Other(value.to_string())
38    }
39}