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    /// No supported subtitle track (ASS or SRT) found in the MKV.
40    #[error("no supported subtitle track found in {path}")]
41    NoSubtitleTrack { path: PathBuf },
42
43    /// Malformed ASS subtitle file.
44    #[error("ASS parse error: {message}")]
45    AssParse { message: String },
46
47    /// Malformed SRT subtitle file.
48    #[error("SRT parse error: {message}")]
49    SrtParse { message: String },
50
51    /// Malformed WebVTT subtitle file.
52    #[error("WebVTT parse error: {message}")]
53    VttParse { message: String },
54
55    /// LLM returned invalid numbered text (missing IDs, duplicates, etc.).
56    #[error("translation response is invalid: {message}")]
57    InvalidTranslation { message: String },
58
59    /// Translation provider returned an error.
60    #[error("{provider} error: {message}")]
61    Translation {
62        provider: &'static str,
63        message: String,
64    },
65}
66
67/// Convenience alias for `Result<T, SubtitleToolkitError>`.
68pub type Result<T> = std::result::Result<T, SubtitleToolkitError>;