recovery.rs (2776B)
1 use tera_core::error::recovery; 2 3 #[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Enum)] 4 pub enum FfiRecoveryDisposition { 5 Unknown, 6 InvalidInput, 7 StaleRevision, 8 IdempotencyConflict, 9 StaleCursor, 10 ProtectedDataUnavailable, 11 IdentityUnavailable, 12 StorageFailure, 13 QuotaExhausted, 14 CancelledBeforeEffect, 15 OutcomeUnknown, 16 UnsupportedVersion, 17 NetworkUnavailable, 18 PartialResult, 19 NetworkPolicy, 20 MediaCorrupt, 21 RuntimeUnavailable, 22 } 23 24 #[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Enum)] 25 pub enum FfiRetryDisposition { 26 NotAllowed, 27 AfterRecovery, 28 ReconcileExistingOperation, 29 } 30 31 #[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Record)] 32 pub struct FfiRecoveryDecision { 33 pub disposition: FfiRecoveryDisposition, 34 pub retry: FfiRetryDisposition, 35 } 36 37 /// Pure guidance; never admits, retries, or publishes an operation. 38 #[uniffi::export] 39 pub fn classify_error_recovery(schema_version: u16, code: String) -> FfiRecoveryDecision { 40 let decision = recovery::classify(schema_version, &code); 41 let retry = match decision.retry { 42 recovery::RetryDisposition::NotAllowed => FfiRetryDisposition::NotAllowed, 43 recovery::RetryDisposition::AfterRecovery => FfiRetryDisposition::AfterRecovery, 44 recovery::RetryDisposition::ReconcileExistingOperation => { 45 FfiRetryDisposition::ReconcileExistingOperation 46 } 47 }; 48 FfiRecoveryDecision { 49 disposition: decision.disposition.into(), 50 retry, 51 } 52 } 53 54 impl From<recovery::RecoveryDisposition> for FfiRecoveryDisposition { 55 fn from(value: recovery::RecoveryDisposition) -> Self { 56 use recovery::RecoveryDisposition as Core; 57 match value { 58 Core::Unknown => Self::Unknown, 59 Core::InvalidInput => Self::InvalidInput, 60 Core::StaleRevision => Self::StaleRevision, 61 Core::IdempotencyConflict => Self::IdempotencyConflict, 62 Core::StaleCursor => Self::StaleCursor, 63 Core::ProtectedDataUnavailable => Self::ProtectedDataUnavailable, 64 Core::IdentityUnavailable => Self::IdentityUnavailable, 65 Core::StorageFailure => Self::StorageFailure, 66 Core::QuotaExhausted => Self::QuotaExhausted, 67 Core::CancelledBeforeEffect => Self::CancelledBeforeEffect, 68 Core::OutcomeUnknown => Self::OutcomeUnknown, 69 Core::UnsupportedVersion => Self::UnsupportedVersion, 70 Core::NetworkUnavailable => Self::NetworkUnavailable, 71 Core::PartialResult => Self::PartialResult, 72 Core::NetworkPolicy => Self::NetworkPolicy, 73 Core::MediaCorrupt => Self::MediaCorrupt, 74 Core::RuntimeUnavailable => Self::RuntimeUnavailable, 75 } 76 } 77 }