lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

restore_capability.rs (2288B)


      1 use core::fmt;
      2 
      3 /// Path-free failures from actual owner restore operations. These are not
      4 /// optimistic reliability-record transition errors or permission to deliver
      5 /// historical operations after reopening restored storage.
      6 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
      7 #[non_exhaustive]
      8 pub enum RestoreCapabilityError {
      9     /// The backend provides no actual restore capability.
     10     Unsupported,
     11     /// The owner is closed, unavailable or not writable.
     12     Unavailable,
     13     /// An explicit valid host-owned backup location is required.
     14     InvalidConfiguration,
     15     /// The retained backup format is unsupported.
     16     UnsupportedVersion,
     17     /// Existing staging or recovery state requires reconciliation.
     18     Conflict,
     19     /// The supplied inventory or retained members could not be verified.
     20     VerificationFailed,
     21     /// Staging or installation did not complete; retain recovery evidence.
     22     Failed,
     23 }
     24 
     25 impl fmt::Display for RestoreCapabilityError {
     26     fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
     27         formatter.write_str(match self {
     28             Self::Unsupported => "storage restore capability is unsupported",
     29             Self::Unavailable => "storage restore owner is unavailable",
     30             Self::InvalidConfiguration => "storage restore configuration is invalid",
     31             Self::UnsupportedVersion => "storage restore format is unsupported",
     32             Self::Conflict => "storage restore state requires reconciliation",
     33             Self::VerificationFailed => "storage restore verification failed",
     34             Self::Failed => "storage restore did not complete",
     35         })
     36     }
     37 }
     38 
     39 impl std::error::Error for RestoreCapabilityError {}
     40 
     41 #[cfg(test)]
     42 mod tests {
     43     use super::RestoreCapabilityError as E;
     44 
     45     #[test]
     46     fn restore_errors_expose_only_bounded_public_reports() {
     47         for error in [
     48             E::Unsupported,
     49             E::Unavailable,
     50             E::InvalidConfiguration,
     51             E::UnsupportedVersion,
     52             E::Conflict,
     53             E::VerificationFailed,
     54             E::Failed,
     55         ] {
     56             let report = error.to_string();
     57             assert!(report.len() < 80);
     58             assert!(!report.contains('/'));
     59             assert!(std::error::Error::source(&error).is_none());
     60         }
     61     }
     62 }