changeset_saga/error.rs
1use std::fmt::Debug;
2
3use thiserror::Error;
4
5/// Error from a failed compensation operation.
6#[derive(Debug, thiserror::Error)]
7#[error("compensation failed for step '{step}': {description}")]
8pub struct CompensationError<E> {
9 /// Name of the step whose compensation failed.
10 pub step: String,
11 /// Description of what the compensation was trying to do.
12 pub description: String,
13 /// The underlying error.
14 #[source]
15 pub error: E,
16}
17
18/// Error from saga execution.
19#[derive(Debug, Error)]
20#[non_exhaustive]
21pub enum SagaError<E: Debug> {
22 /// A step failed and all compensations succeeded.
23 #[error("step '{step}' failed")]
24 StepFailed {
25 /// Name of the step that failed.
26 step: String,
27 /// The error that caused the step to fail.
28 #[source]
29 source: E,
30 },
31
32 /// A step failed and some compensations also failed.
33 #[error("step '{failed_step}' failed, and {} compensation(s) also failed", compensation_errors.len())]
34 CompensationFailed {
35 /// Name of the step that originally failed.
36 failed_step: String,
37 /// The error from the failed step.
38 step_error: E,
39 /// Errors from failed compensations.
40 compensation_errors: Vec<CompensationError<E>>,
41 },
42}