Skip to main content

psyche_subtitle_toolkit/
error.rs

1use std::io;
2use std::path::PathBuf;
3
4/// Errors produced by the subtitle toolkit.
5#[derive(Debug, thiserror::Error)]
6pub enum SubtitleToolkitError {
7    /// Standard I/O error.
8    #[error("I/O error: {0}")]
9    Io(#[from] io::Error),
10
11    /// HTTP request error (Ollama API).
12    #[error("HTTP error: {0}")]
13    Http(#[from] reqwest::Error),
14
15    /// JSON serialization/deserialization error.
16    #[error("JSON error: {0}")]
17    Json(#[from] serde_json::Error),
18
19    /// Required external tool (e.g. `mkvmerge`, `mkvextract`) not found in PATH.
20    #[error("required tool `{tool}` was not found in PATH")]
21    MissingTool { tool: &'static str },
22
23    /// External command returned a nonzero exit status.
24    #[error("command `{program}` failed with status {status}: {stderr}")]
25    CommandFailed {
26        program: &'static str,
27        status: String,
28        stderr: String,
29    },
30
31    /// No `.mkv` files found at the given path.
32    #[error("no MKV files found at {path}")]
33    NoMkvFiles { path: PathBuf },
34
35    /// No ASS/SSA subtitle track found in the MKV.
36    #[error("no ASS subtitle track found in {path}")]
37    NoAssTrack { path: PathBuf },
38
39    /// Malformed ASS subtitle file.
40    #[error("ASS parse error: {message}")]
41    AssParse { message: String },
42
43    /// LLM returned invalid numbered text (missing IDs, duplicates, etc.).
44    #[error("translation response is invalid: {message}")]
45    InvalidTranslation { message: String },
46
47    /// Translation provider returned an error.
48    #[error("{provider} error: {message}")]
49    Translation {
50        provider: &'static str,
51        message: String,
52    },
53}
54
55/// Convenience alias for `Result<T, SubtitleToolkitError>`.
56pub type Result<T> = std::result::Result<T, SubtitleToolkitError>;