use happenstance_core::{InvalidEventType, InvalidTag};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum PostgresEventStoreError {
#[error("postgres rejected the work")]
Driver(#[from] sqlx::Error),
#[error("stored position {value} is not a valid sequence position")]
PositionOutOfRange {
value: i64,
},
#[error("stored event type is not valid: {0}")]
EventType(#[source] InvalidEventType),
#[error("stored tag is not valid: {0}")]
Tag(#[source] InvalidTag),
#[error(
"this store has no identity: `store_meta` has no `store_id` row, so migration 1 has probably not been applied to this schema"
)]
MissingIdentity,
#[error("this store's identity is {len} bytes, and a `StoreId` is exactly 16")]
MalformedIdentity {
len: usize,
},
#[error(
"the event at position {position} carries no origin identity; it was not written by this adapter"
)]
UnstampedEvent {
position: happenstance_core::SequencePosition,
},
#[error("the task this read handed its work to did not finish")]
Worker(#[from] tokio::task::JoinError),
#[error(
"this read stream was polled outside a tokio runtime, and it needs one to open its snapshot"
)]
NoRuntime,
#[error(
"a row's `xact_id` could not be read as an xid8; the schema is not the one this adapter wrote"
)]
UnreadableTransactionId,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum PostgresProjectionStoreError {
#[error("postgres rejected the work")]
Driver(#[from] sqlx::Error),
#[error("stored checkpoint {value} is not a valid sequence position")]
CheckpointOutOfRange {
value: i64,
},
#[error("stored checkpoint authority {0:?} is neither `live` nor `rebuilding`")]
InvalidAuthority(String),
#[error("the batch was begun on a different store instance")]
ForeignBatch,
#[error(
"statement {statement} binds {supplied} values, and its text uses placeholders up to ${declared}"
)]
#[non_exhaustive]
ParameterCount {
statement: usize,
declared: usize,
supplied: usize,
},
#[error(
"a statement in this batch was refused before it reached the server, so the batch cannot commit"
)]
Poisoned,
}