#![allow(clippy::module_inception)]
use thiserror::Error;
pub type Result<T> = std::result::Result<T, LlamaError>;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum LlamaError {
#[error("I/O: {0}")]
Io(#[from] std::io::Error),
#[error("interior nul byte in string: {0}")]
Nul(#[from] std::ffi::NulError),
#[error("invalid utf-8: {0}")]
Utf8(#[from] std::string::FromUtf8Error),
#[error("invalid utf-8: {0}")]
Utf8Lossy(#[from] std::str::Utf8Error),
#[error("failed to load model: {0}")]
ModelLoad(String),
#[error("failed to create context: {0}")]
ContextLoad(String),
#[error("decode failed (code {0})")]
Decode(i32),
#[error("encode failed (code {0})")]
Encode(i32),
#[error("batch error: {0}")]
Batch(String),
#[error("embedding error: {0}")]
Embedding(String),
#[error("backend not initialized")]
BackendNotInitialized,
#[error("json schema to grammar: {0}")]
JsonSchemaToGrammar(String),
#[error("chat template: {0}")]
ChatTemplate(String),
#[error("C-ABI error (code {0})")]
Ffi(i32),
}
impl LlamaError {
#[must_use]
pub fn null_return() -> Self {
Self::Ffi(-1)
}
}
impl From<std::num::TryFromIntError> for LlamaError {
fn from(e: std::num::TryFromIntError) -> Self {
Self::Batch(e.to_string())
}
}