Skip to main content

abyo_speculate/
error.rs

1//! Crate error types.
2
3use thiserror::Error;
4
5/// Result alias used throughout the crate.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// All errors that abyo-speculate can return.
9#[derive(Debug, Error)]
10pub enum Error {
11    /// A required builder field was not set.
12    #[error("missing required builder field: {0}")]
13    MissingField(&'static str),
14
15    /// The requested model is not in the recognized preset list.
16    #[error("unknown model preset: {0}")]
17    UnknownPreset(String),
18
19    /// The requested SD method does not support the requested operation in this configuration.
20    #[error("method {method} unsupported here: {reason}")]
21    UnsupportedMethod {
22        /// The method name (e.g. "Medusa").
23        method: &'static str,
24        /// Why it's unsupported in this context.
25        reason: String,
26    },
27
28    /// A KV-cache snapshot could not be restored (rollback misuse).
29    #[error("invalid KV-cache rollback: {0}")]
30    CacheRollback(String),
31
32    /// Sampling produced an invalid distribution (NaN, all-zero, etc).
33    #[error("invalid sampling distribution: {0}")]
34    Sampling(String),
35
36    /// Pass-through for [`candle_core::Error`].
37    #[error(transparent)]
38    Candle(#[from] candle_core::Error),
39
40    /// Pass-through for tokenizer errors.
41    #[error("tokenizer error: {0}")]
42    Tokenizer(String),
43
44    /// Pass-through for model-load / IO errors.
45    #[error(transparent)]
46    Io(#[from] std::io::Error),
47
48    /// Anything not yet specifically classified.
49    #[error(transparent)]
50    Other(#[from] anyhow::Error),
51}
52
53impl From<tokenizers::Error> for Error {
54    fn from(e: tokenizers::Error) -> Self {
55        Error::Tokenizer(e.to_string())
56    }
57}