use std::path::PathBuf;
use thiserror::Error;
pub type Result<T, E = BbpeError> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum BbpeError {
#[error("invalid configuration: {0}")]
InvalidConfig(String),
#[error("io error while processing {path:?}: {source}")]
Io {
source: std::io::Error,
path: Option<PathBuf>,
},
#[error("huggingface tokenizers error: {0}")]
Tokenizers(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("internal error: {0}")]
Internal(String),
}
impl From<tokenizers::Error> for BbpeError {
fn from(err: tokenizers::Error) -> Self {
Self::Tokenizers(err.to_string())
}
}
impl From<serde_json::Error> for BbpeError {
fn from(err: serde_json::Error) -> Self {
Self::Serialization(err.to_string())
}
}
impl BbpeError {
pub fn io(source: std::io::Error, path: Option<PathBuf>) -> Self {
Self::Io { source, path }
}
}