use smol_str::SmolStr;
use thiserror::Error;
pub type WhisperResult<T> = Result<T, WhisperError>;
#[derive(Debug, Error)]
pub enum WhisperError {
#[error("failed to load model from {path}: {reason}")]
ContextLoad {
path: SmolStr,
reason: SmolStr,
},
#[error("failed to allocate whisper state")]
StateInit,
#[error("Context was poisoned by a prior StateLost; drop and reconstruct to recover")]
ContextPoisoned,
#[error(
"whisper.cpp init threw {origin} (sentinel {code}); native partial allocation leaked, \
not retryable"
)]
ConstructorLost {
origin: &'static str,
code: i32,
},
#[error("whisper_full failed with code {code}")]
Full {
code: i32,
},
#[error("whisper_full lost the native state (code {code}); state freed, Context poisoned")]
StateLost {
code: i32,
},
#[error("argument contained an interior NUL byte: {0}")]
InvalidCString(SmolStr),
#[error("whisper.cpp returned non-UTF-8 text: {0}")]
Utf8(#[from] core::str::Utf8Error),
#[error("audio buffer too large: {samples} samples > i32::MAX")]
SamplesOverflow {
samples: usize,
},
#[error(
"audio buffer too short: {samples} samples < {min_required} (reflective-pad lower bound)"
)]
SamplesTooShort {
samples: usize,
min_required: usize,
},
#[error("token id {token} out of range [0, {vocab_size})")]
TokenOutOfRange {
token: i32,
vocab_size: i32,
},
}