use thiserror::Error; #[derive(Debug, Error)] pub enum TesseraError { #[error("vault is locked: {0}")] VaultLocked(String), #[error("wrong passphrase")] WrongPassphrase, #[error("provider unreachable: {0}")] ProviderUnreachable(String), #[error("disk full: need {needed} bytes")] DiskFull { needed: u64 }, #[error("{0}")] UserMessage(String), } impl TesseraError { pub fn user_message(&self) -> &str { match self { TesseraError::VaultLocked(_) => { "Another orbit is still circling the vault. Try again when it finishes." } TesseraError::WrongPassphrase => "That key doesn't unlock this vault.", TesseraError::ProviderUnreachable(_) => { "We couldn't reach the source at this outpost." } TesseraError::DiskFull { .. } => { "The vault is out of space—free room or widen the hold." } TesseraError::UserMessage(m) => m.as_str(), } } }