use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error(
"{operation} is not implemented yet: this build of onevcs is interface-only \
(the approved contract is in docs/contract.md)"
)]
NotImplemented {
operation: &'static str,
},
#[error("gate failed: {reason}")]
GateFailed {
reason: String,
},
#[error("invalid input: {reason}")]
Invalid {
reason: String,
},
#[error("sync conflict: {reason}")]
SyncConflict {
reason: String,
},
}
pub type Result<T> = std::result::Result<T, Error>;
pub(crate) fn invalid(reason: impl Into<String>) -> Error {
Error::Invalid {
reason: reason.into(),
}
}
pub(crate) fn at<'a, E: std::fmt::Display>(
action: &'static str,
path: &'a std::path::Path,
) -> impl FnOnce(E) -> Error + 'a {
move |error| invalid(format!("cannot {action} {}: {error}", path.display()))
}