1#[cfg(doc)]
23use crate::options::EipsOptions;
24use core::fmt::{self, Debug, Display};
25
26#[non_exhaustive]
30#[derive(Clone, Copy, Debug)]
31pub enum ChangeError<Id> {
32 BadParentId(Id),
34
35 BadDirection(Id),
38
39 MergeConflict(Id),
42
43 UnsupportedMove(Id),
50
51 BadOldLocation(Id),
53
54 UnexpectedMove(Id),
57
58 OldLocationIsMove(Id),
61
62 HiddenMove(Id),
65
66 TimestampOverflow {
75 id: Id,
76 timestamp: crate::MoveTimestamp,
77 },
78}
79
80impl<Id> ChangeError<Id> {
81 pub(crate) fn to_basic(&self) -> BasicChangeError {
82 use BasicChangeError as Basic;
83 match self {
84 Self::BadParentId(_) => Basic::BadParentId,
85 Self::BadDirection(_) => Basic::BadDirection,
86 Self::MergeConflict(_) => Basic::MergeConflict,
87 Self::UnsupportedMove(_) => Basic::UnsupportedMove,
88 Self::BadOldLocation(_) => Basic::BadOldLocation,
89 Self::UnexpectedMove(_) => Basic::UnexpectedMove,
90 Self::OldLocationIsMove(_) => Basic::OldLocationIsMove,
91 Self::HiddenMove(_) => Basic::HiddenMove,
92 Self::TimestampOverflow {
93 timestamp,
94 ..
95 } => Basic::TimestampOverflow {
96 timestamp: *timestamp,
97 },
98 }
99 }
100}
101
102impl<Id: Display> Display for ChangeError<Id> {
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 let basic = self.to_basic();
105 match self {
106 Self::BadParentId(id) => write!(f, "{basic}: {id}"),
107 Self::BadDirection(id) => write!(f, "{basic}: {id}"),
108 Self::MergeConflict(id) => write!(f, "{basic}: {id}"),
109 Self::UnsupportedMove(id) => write!(f, "{basic}: {id}"),
110 Self::BadOldLocation(id) => write!(f, "{basic}: {id}"),
111 Self::UnexpectedMove(id) => write!(f, "{basic}: {id}"),
112 Self::OldLocationIsMove(id) => write!(f, "{basic}: {id}"),
113 Self::HiddenMove(id) => write!(f, "{basic}: {id}"),
114 Self::TimestampOverflow {
115 id,
116 ..
117 } => write!(f, "{basic} (id {id})"),
118 }
119 }
120}
121
122#[cfg(feature = "std")]
123#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "std")))]
124impl<Id: Debug + Display> std::error::Error for ChangeError<Id> {}
125
126#[non_exhaustive]
128#[derive(Clone, Copy, Debug)]
129pub struct IndexError {
130 pub index: usize,
132}
133
134impl Display for IndexError {
135 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
136 write!(fmt, "bad index: {}", self.index)
137 }
138}
139
140#[cfg(feature = "std")]
141#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "std")))]
142impl std::error::Error for IndexError {}
143
144#[non_exhaustive]
146#[derive(Clone, Copy, Debug)]
147pub struct IdError<Id> {
148 pub id: Id,
150}
151
152impl<Id: Display> Display for IdError<Id> {
153 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
154 write!(fmt, "bad id: {}", self.id)
155 }
156}
157
158#[cfg(feature = "std")]
159#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "std")))]
160impl<Id: Debug + Display> std::error::Error for IdError<Id> {}
161
162#[derive(Clone, Copy, Debug)]
163pub(crate) enum BasicChangeError {
164 BadParentId,
165 BadDirection,
166 MergeConflict,
167 UnsupportedMove,
168 BadOldLocation,
169 UnexpectedMove,
170 OldLocationIsMove,
171 HiddenMove,
172 TimestampOverflow {
173 timestamp: crate::MoveTimestamp,
174 },
175}
176
177impl Display for BasicChangeError {
178 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179 match self {
180 Self::BadParentId => write!(f, "bad parent id"),
181 Self::BadDirection => {
182 write!(f, "change has no parent but its direction is 'before'")
183 }
184 Self::MergeConflict => {
185 write!(f, "conflict between change and existing data")
186 }
187 Self::UnsupportedMove => {
188 write!(f, "change has move info but moves are unsupported")
189 }
190 Self::BadOldLocation => write!(f, "bad old location"),
191 Self::UnexpectedMove => {
192 write!(f, "change has no move info but is a move destination")
193 }
194 Self::OldLocationIsMove => {
195 write!(f, "old location is a move destination")
196 }
197 Self::HiddenMove => {
198 write!(f, "change is a move destination but is hidden")
199 }
200 Self::TimestampOverflow {
201 timestamp,
202 } => write!(f, "move timestamp is too large: {timestamp}"),
203 }
204 }
205}