use super::Timestamp;
use crate::Version;
#[derive(Debug, thiserror::Error)]
pub enum LogHistoryError {
#[error("Invalid timestamp range: ({start_timestamp}, {end_timestamp})")]
InvalidTimestampRange {
start_timestamp: Timestamp,
end_timestamp: Timestamp,
},
#[error(
"There are no commits in the timestamp range ({start_timestamp}, {end_timestamp}). \
The entire timestamp range falls between versions {between_version} and {}.",
.between_version + 1
)]
EmptyTimestampRange {
start_timestamp: Timestamp,
end_timestamp: Timestamp,
between_version: Version,
},
#[error("Timestamp {timestamp} is out of range: {reason}")]
TimestampOutOfRange {
timestamp: Timestamp,
reason: &'static str,
},
#[error("{context}{}", source.as_ref().map(|e| format!(": {e}")).unwrap_or_default())]
Internal {
context: &'static str,
#[source]
source: Option<Box<crate::Error>>,
},
}
impl LogHistoryError {
pub(crate) fn internal(context: &'static str, source: crate::Error) -> Self {
Self::Internal {
context,
source: Some(Box::new(source)),
}
}
pub(crate) fn internal_message(context: &'static str) -> Self {
Self::Internal {
context,
source: None,
}
}
}
impl From<LogHistoryError> for crate::Error {
fn from(e: LogHistoryError) -> Self {
crate::Error::LogHistory(Box::new(e))
}
}