1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use std::error::Error;
use eventcore_types::{DeliveryPosition, DeliverySourceId, ProjectionSelectionId, ProjectorName};
use thiserror::Error;
use super::ProjectionConfigurationError;
/// Type-erased failure source retained by the stable runner error boundary.
pub type BoxedProjectionError = Box<dyn Error + Send + Sync>;
/// Terminal failures from a transactional projection run.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TransactionalProjectionError {
/// Another process owns this projector's read-model leadership lock.
#[error("transactional projection leadership is busy")]
LeadershipBusy,
/// The leader session was lost and can no longer authorize writes.
#[error("transactional projection leadership was lost")]
LeadershipLost {
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// The event source could not provide a page or high-water mark.
#[error("transactional projection source failed")]
Source {
/// Underlying source error.
#[source]
source: BoxedProjectionError,
},
/// A selected persisted payload could not decode into the application's event contract.
#[error("transactional projection could not decode event at position {position:?}")]
Decode {
/// Position of the malformed selected envelope.
position: DeliveryPosition,
/// Underlying deserialization error.
#[source]
source: BoxedProjectionError,
},
/// The projector chose the `Fatal` decision for an application error.
#[error("transactional projection application failed at position {position:?}")]
Application {
/// Failed position.
position: DeliveryPosition,
/// Underlying application error.
#[source]
source: BoxedProjectionError,
},
/// Retry attempts were exhausted without committing the event effect.
#[error("transactional projection retries exhausted at position {position:?}")]
RetryExhausted {
/// Failed position.
position: DeliveryPosition,
/// Total application invocations, including the initial attempt.
attempts: u32,
/// Last application error.
#[source]
source: BoxedProjectionError,
},
/// Progress could not be loaded or advanced for the pending delivery position.
#[error("transactional projection progress operation failed at position {position:?}")]
Progress {
/// Delivery position whose transaction remains pending.
position: DeliveryPosition,
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// A progress storage operation without a pending delivery position failed.
#[error("transactional projection progress storage operation failed")]
ProgressStore {
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// PostgreSQL did not acknowledge the commit, so durable state must be inspected on recovery.
#[error("transactional projection commit acknowledgement is indeterminate")]
CommitIndeterminate {
/// Position whose transaction may or may not have committed.
position: DeliveryPosition,
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// Existing progress belongs to a different delivery source.
#[error("transactional projection source identity does not match {projector}")]
SourceIdentityMismatch {
/// Projector whose durable identity was incompatible.
projector: ProjectorName,
/// Source identity persisted with durable progress.
persisted: DeliverySourceId,
/// Source identity configured for this invocation.
configured: DeliverySourceId,
},
/// Existing progress belongs to a different projection selection.
#[error("transactional projection selection identity does not match {projector}")]
SelectionIdentityMismatch {
/// Projector whose durable identity was incompatible.
projector: ProjectorName,
/// Selection identity persisted with durable progress.
persisted: ProjectionSelectionId,
/// Selection identity configured for this invocation.
configured: ProjectionSelectionId,
},
/// Configuration cannot safely start a projection.
#[error("transactional projection configuration is invalid")]
Configuration {
/// Invalid configuration detail.
#[source]
source: ProjectionConfigurationError,
},
/// A confirmed commit succeeded but its after-commit action failed.
#[error(
"transactional projection after-commit action failed at position {committed_position:?}"
)]
AfterCommitFailed {
/// Already committed position.
committed_position: DeliveryPosition,
/// Underlying hook error.
#[source]
source: BoxedProjectionError,
},
}
/// Failures from a coordinated basic reset.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ProjectionResetError {
/// Another invocation owns this projector's leadership grant.
#[error("transactional projection reset leadership is busy")]
Busy,
/// The leader session was lost while starting, rolling back, or releasing the reset.
///
/// A release failure can occur after the reset commit was acknowledged. Callers must not
/// infer from this variant that the reset was rolled back or did not commit.
#[error("transactional projection reset leadership was lost")]
LeadershipLost {
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// Existing progress belongs to a different delivery source.
#[error("transactional projection reset source identity does not match {projector}")]
SourceIdentityMismatch {
/// Projector whose durable identity was incompatible.
projector: ProjectorName,
/// Source identity persisted with durable progress.
persisted: DeliverySourceId,
/// Source identity configured for this reset.
configured: DeliverySourceId,
},
/// Existing progress belongs to a different projection selection.
#[error("transactional projection reset selection identity does not match {projector}")]
SelectionIdentityMismatch {
/// Projector whose durable identity was incompatible.
projector: ProjectorName,
/// Selection identity persisted with durable progress.
persisted: ProjectionSelectionId,
/// Selection identity configured for this reset.
configured: ProjectionSelectionId,
},
/// Application reset code failed and its transaction was rolled back.
#[error("transactional projection reset callback failed")]
Callback {
/// Underlying application error.
#[source]
source: BoxedProjectionError,
},
/// Progress validation or deletion failed before commit.
#[error("transactional projection reset progress operation failed")]
Progress {
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
/// PostgreSQL did not acknowledge the reset commit, so durable state is indeterminate.
#[error("transactional projection reset commit acknowledgement is indeterminate")]
CommitIndeterminate {
/// Underlying database error.
#[source]
source: BoxedProjectionError,
},
}
/// Failures from the reset-and-replay convenience operation.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ProjectionResetAndReplayError {
/// The coordinated reset phase failed.
#[error("transactional projection reset phase failed")]
Reset(#[source] ProjectionResetError),
/// The replay phase failed after reset committed.
#[error("transactional projection replay phase failed")]
Replay(#[source] TransactionalProjectionError),
}