1use crate::id::{IdError, RecordId};
2use crate::validation::ValidationErrors;
3
4pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 #[error(transparent)]
9 Id(#[from] IdError),
10 #[error(transparent)]
11 Validation(#[from] ValidationErrors),
12 #[error("record not found: {0}")]
13 NotFound(RecordId),
14 #[error("version conflict on {id}: expected version {expected}, current version is {actual}")]
15 Conflict { id: RecordId, expected: u64, actual: u64 },
16 #[error("idempotency key {0:?} was already used for a different command")]
17 IdempotencyConflict(String),
18 #[error("operation not permitted: {0}")]
19 NotPermitted(String),
20 #[error("invalid history: {0}")]
21 Projection(String),
22 #[error("storage error: {0}")]
23 Storage(String),
24 #[error("serialization error: {0}")]
25 Serialization(String),
26 #[error("import rejected: {0}")]
27 Import(String),
28}
29
30impl From<serde_json::Error> for Error {
31 fn from(e: serde_json::Error) -> Self {
32 Error::Serialization(e.to_string())
33 }
34}