error.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //! Error types for storage implementations.
  2. use kuatia_types::AccountId;
  3. /// Errors produced by [`Store`](crate::store::Store) implementations.
  4. ///
  5. /// The store is a dumb instruction follower: writes report affected-row counts,
  6. /// not semantic verdicts, so there are no "posting not active"/"reservation
  7. /// mismatch"/"cas conflict" variants — the saga derives those from counts.
  8. #[derive(Debug)]
  9. pub enum StoreError {
  10. /// The requested entity was not found.
  11. NotFound(String),
  12. /// The entity already exists (e.g. duplicate account creation).
  13. AlreadyExists(String),
  14. /// Optimistic version check failed on an account update.
  15. VersionConflict {
  16. /// Account that had a version mismatch.
  17. account: AccountId,
  18. /// Version the caller expected.
  19. expected: u64,
  20. /// Version the store actually had.
  21. actual: u64,
  22. },
  23. /// Catch-all for unexpected internal errors.
  24. Internal(String),
  25. }
  26. impl std::fmt::Display for StoreError {
  27. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  28. match self {
  29. Self::NotFound(msg) => write!(f, "not found: {msg}"),
  30. Self::AlreadyExists(msg) => write!(f, "already exists: {msg}"),
  31. Self::VersionConflict {
  32. account,
  33. expected,
  34. actual,
  35. } => {
  36. write!(
  37. f,
  38. "version conflict for {account:?}: expected {expected}, got {actual}"
  39. )
  40. }
  41. Self::Internal(msg) => write!(f, "internal error: {msg}"),
  42. }
  43. }
  44. }
  45. impl std::error::Error for StoreError {}