Skip to main content

PostgresEventStoreError

Enum PostgresEventStoreError 

#[non_exhaustive]
pub enum PostgresEventStoreError {
Show 13 variants Driver(Error), PositionOutOfRange { value: i64, }, EventType(InvalidEventType), Tag(InvalidTag), MissingIdentity, MalformedIdentity { len: usize, }, UnstampedEvent { position: SequencePosition, }, Worker(JoinError), NoRuntime, UnreadableTransactionId, OriginPositionOutOfRange { position: SequencePosition, }, StoredGuard { first: SequencePosition, source: GuardCodecError, }, GroupOrder(GroupOrderError),
}
Expand description

How PostgresEventStore fails for its own reasons.

The decoding variants are not defensive padding. A row is written by one version of this adapter and read back by another, and the contract types enforce invariants that the Postgres column types do not: position is bigint, which is signed and admits 0 and negatives, while SequencePosition is a NonZeroU64; event_type and tag are text, which admits control characters and over-long values that EventType and Tag reject. Every one of those is a real row a real database can hand back, and the alternative to a variant is a panic in a library.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Driver(Error)

The driver, the pool or the server rejected the work.

This is the common case and it is deliberately not flattened into per-SQLSTATE variants: sqlx::Error::Database already exposes the code through DatabaseError::code, and a variant per code would be a second, worse copy of that.

§

PositionOutOfRange

A row carried a position outside the contract’s domain.

bigint is signed and admits zero; SequencePosition is a NonZeroU64. The gap between the two is exactly this variant.

Fields

§value: i64

The value as Postgres returned it.

§

EventType(InvalidEventType)

A row carried an event_type that no longer passes validation.

§

Tag(InvalidTag)

A row carried a tag that no longer passes validation.

§

MissingIdentity

store_meta has no store_id row.

Almost always means migration 1 has not been applied to the schema this pool resolves against. Spelled as its own variant rather than as a Driver error because “the schema is not there” and “the server refused the query” send a reader to entirely different places, and at 2am the difference is the whole diagnosis.

§

MalformedIdentity

The store_id row is not sixteen bytes.

StoreId is [u8; 16] exactly, and the schema’s CHECK says so — so reaching this means something wrote the row without going through either.

Fields

§len: usize

The length actually stored.

§

UnstampedEvent

A row carries no EventId.

Every event this store appends is stamped with origin_store and origin_position in the same statement that inserts it, so a row missing either was written by something other than this adapter. Reported rather than papered over with a synthesised id, because a synthesised EventId is a replication identity this store has no authority to mint.

Fields

§position: SequencePosition

Where the unstamped row sits.

§

Worker(JoinError)

The task a read stream handed its work to did not finish.

read spawns the cursor’s opening onto the runtime rather than polling it inline, so that the read’s state is fixed no later than the first poll (ES-11) rather than whenever the caller next gets round to polling. A spawned task can panic or be cancelled, and neither is something the caller can act on — but ending the stream silently would look exactly like an empty log, which is why this is an error rather than a None.

§

NoRuntime

read was polled outside a tokio runtime.

The stream needs a runtime to hand its work to, and read is not async — deliberately, because nesting the stream inside a future drops + Send from it — so nothing forces the caller to be on one. Reported rather than panicked: a library that panics on a legitimate call pattern has made the caller’s mistake into its own crash.

§

UnreadableTransactionId

A row’s xact_id could not be read as the mechanism’s frontier type.

The visibility mechanism stores pg_current_xact_id() beside each row and compares it against pg_snapshot_xmin(pg_current_snapshot()). A value that will not decode means the column is not the one this adapter wrote, which is a schema disagreement rather than a transient fault — worth its own name because every other symptom of it is a wrong answer rather than an error.

§

OriginPositionOutOfRange

Available on crate feature sync only.

An ingested event’s origin position is past the largest a bigint holds, so it cannot be stored. Refused before the transaction opens.

Produced only by ingest, behind sync. The enum is #[non_exhaustive], so a variant that appears under a feature breaks no exhaustive match.

Fields

§position: SequencePosition

The origin position as the peer sent it.

§

StoredGuard

Available on crate feature sync only.

The guard of a write group could not be put into group_guard on its way in, or read back out of it (#420).

On the way in the ingest’s transaction is rolled back, so nothing in the call was written. On the way out the stored bytes are not a guard this build’s codec reads, which only a damaged schema or a newer build’s format holds; the group is not forwarded without it. Behind sync, for the reason OriginPositionOutOfRange is.

Fields

§first: SequencePosition

The write group the guard belongs to.

§source: GuardCodecError

Why the codec refused it.

§

GroupOrder(GroupOrderError)

Available on crate feature sync only.

The group read handed its page builder a row naming a write group it had already passed, so the log cannot be paged in whole groups.

The read orders its rows by group, so no schema this adapter wrote produces one; a hand-edited write_group can. Behind sync, for the reason OriginPositionOutOfRange is.

Trait Implementations§

§

impl Classify for PostgresEventStoreError

Available on crate features event-store and sync only.

SY-36’s class for each way this adapter fails.

Exhaustive over this crate’s own enum, with no wildcard, so a new variant does not compile until somebody decides its class. A driver failure is transient when the server aborted or never started the work and time or an operator cures it: the network, the pool, a serialisation failure, a deadlock, an administrator’s shutdown, or exhausted resources. Every other driver failure, and every decoding variant, fails the same way again.

§

fn class(&self) -> FailureClass

The remedy this failure calls for.
§

impl Debug for PostgresEventStoreError

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Display for PostgresEventStoreError

§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Error for PostgresEventStoreError

§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
§

impl From<Error> for PostgresEventStoreError

§

fn from(source: Error) -> Self

Converts to this type from the input type.
§

impl From<GroupOrderError> for PostgresEventStoreError

§

fn from(source: GroupOrderError) -> Self

Converts to this type from the input type.
§

impl From<JoinError> for PostgresEventStoreError

§

fn from(source: JoinError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more