use std::fmt::Display;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ReedlineErrorVariants {
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
#[error("error within history database: {0}")]
HistoryDatabaseError(String),
#[error("error in Reedline history: {0}")]
OtherHistoryError(&'static str),
#[error("the history {history} does not support feature {feature}")]
HistoryFeatureUnsupported {
history: &'static str,
feature: &'static str,
},
#[error("I/O error: {0}")]
IOError(std::io::Error),
}
#[derive(Debug)]
pub struct ReedlineError(pub ReedlineErrorVariants);
impl From<std::io::Error> for ReedlineError {
fn from(err: std::io::Error) -> Self {
Self(ReedlineErrorVariants::IOError(err))
}
}
impl Display for ReedlineError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::error::Error for ReedlineError {}
pub type Result<T> = std::result::Result<T, ReedlineError>;