use super::{execute::ExecutionError, operation::Operation};
#[derive(Debug)]
pub struct SyncError {
operation: Operation,
error: ExecutionError,
}
impl SyncError {
#[must_use]
pub(crate) fn new(operation: Operation, error: ExecutionError) -> Self {
Self { operation, error }
}
}
impl std::fmt::Display for SyncError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.operation {
Operation::FlushStaleMappings { stale_uids } => {
write!(
f,
"Error flushing stale mapping(s) for {stale_uids:?}: {}",
self.error
)
}
Operation::Collection(op) => write!(
f,
"Error executing collection operation {op}: {}",
self.error
),
Operation::Item(op) => write!(f, "Error executing item operation {op}: {}", self.error),
Operation::Property(op) => {
write!(f, "Error executing property operation {op}: {}", self.error)
}
}
}
}
impl std::error::Error for SyncError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}