StatefulSagaResult

sealed interface StatefulSagaResult<out R, out S>

Result of stateful saga execution.

This sealed interface provides type-safe handling of saga execution outcomes, including the final saga state for observability and debugging.

Result Types

  • Completed - Saga completed successfully with result and final state

  • Aborted - Saga aborted due to step failure, all compensations succeeded

  • CompensationFailure - Saga aborted and compensation failed (critical failure)

Usage Example

val result = saga.execute(context)
when (result) {
is StatefulSagaResult.Completed -> {
// All steps succeeded
processResult(result.value)
logFinalState(result.finalState)
}
is StatefulSagaResult.Aborted -> {
// A step failed but all compensations succeeded
logError(result.error)
debugState(result.finalState) // State at time of failure
}
is StatefulSagaResult.CompensationFailure -> {
// Critical failure - manual intervention may be required
alertOps(result.originalError, result.compensationErrors)
captureStateForRecovery(result.finalState)
}
}

Parameters

R

The result type on successful completion

S

The saga state type

Inheritors

Types

Link copied to clipboard
data class Aborted<S>(val error: SagaExecutionError, val finalState: S) : StatefulSagaResult<Nothing, S>

Saga aborted due to step failure.

Link copied to clipboard
data class CompensationFailure<S>(val originalError: SagaExecutionError, val compensationErrors: List<SagaExecutionError>, val finalState: S) : StatefulSagaResult<Nothing, S>

Saga aborted and compensation failed.

Link copied to clipboard
data class Completed<R, S>(val value: R, val finalState: S) : StatefulSagaResult<R, S>

Saga completed successfully with result and final state.