use crate::value::EntityId;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Conflict {
StaleRevision {
expected: u64,
found: u64,
},
MissingTarget {
edit: usize,
id: EntityId,
},
IdAlreadyExists {
edit: usize,
id: EntityId,
},
DanglingReference {
edit: usize,
from: EntityId,
slot: usize,
target: EntityId,
},
RemovalWouldDangle {
edit: usize,
removed: EntityId,
referrer: EntityId,
slot: usize,
},
}
impl std::fmt::Display for Conflict {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::StaleRevision { expected, found } => write!(
f,
"model moved from revision {expected} to {found} since the transaction opened"
),
Self::MissingTarget { edit, id } => {
write!(f, "edit {edit} names #{} which does not exist", id.0)
}
Self::IdAlreadyExists { edit, id } => {
write!(f, "edit {edit} would overwrite existing #{}", id.0)
}
Self::DanglingReference {
edit,
from,
slot,
target,
} => write!(
f,
"edit {edit}: #{}[{slot}] would reference #{} which will not exist",
from.0, target.0
),
Self::RemovalWouldDangle {
edit,
removed,
referrer,
slot,
} => write!(
f,
"edit {edit}: removing #{} leaves #{}[{slot}] dangling",
removed.0, referrer.0
),
}
}
}
impl std::error::Error for Conflict {}