reedline/
result.rs

1use std::fmt::Display;
2use thiserror::Error;
3
4/// non-public (for now)
5#[derive(Error, Debug)]
6pub enum ReedlineErrorVariants {
7    // todo: we should probably be more specific here
8    #[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
9    #[error("error within history database: {0}")]
10    HistoryDatabaseError(String),
11    #[error("error within history: {0}")]
12    OtherHistoryError(&'static str),
13    #[error("the history {history} does not support feature {feature}")]
14    HistoryFeatureUnsupported {
15        history: &'static str,
16        feature: &'static str,
17    },
18    #[error("I/O error: {0}")]
19    IOError(std::io::Error),
20}
21
22/// separate struct to not expose anything to the public (for now)
23#[derive(Debug)]
24pub struct ReedlineError(pub ReedlineErrorVariants);
25
26impl Display for ReedlineError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        self.0.fmt(f)
29    }
30}
31impl std::error::Error for ReedlineError {}
32
33/// Standard [`std::result::Result`], with [`ReedlineError`] as the error variant
34pub type Result<T> = std::result::Result<T, ReedlineError>;