use crate::id::ProfileIx;
pub type Result<T> = std::result::Result<T, AccountError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum AccountError {
#[error("account is locked")]
Locked,
#[error("no profile at index {0}")]
ProfileNotFound(ProfileIx),
#[error("default-profile invariant violated: {0}")]
DefaultProfileInvariant(String),
#[error("keystore error: {0}")]
Keystore(String),
#[error("authentication failed: {0}")]
Auth(String),
#[error("spend refused: {0}")]
Spend(String),
#[error("spend requires explicit authorization: {0}")]
RequireAuth(String),
#[error("spend forbidden by custody policy: {0}")]
PolicyDenied(String),
#[error("spend policy could not be evaluated: {0}")]
PolicyIndeterminate(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn locked_displays() {
assert_eq!(AccountError::Locked.to_string(), "account is locked");
}
#[test]
fn profile_not_found_includes_index() {
let e = AccountError::ProfileNotFound(ProfileIx(2));
assert_eq!(e.to_string(), "no profile at index 2");
}
#[test]
fn keystore_wraps_message() {
let e = AccountError::Keystore("disk full".into());
assert!(e.to_string().contains("disk full"));
}
#[test]
fn the_three_custody_refusals_are_distinct_variants_with_distinct_wording() {
let escalatable = AccountError::RequireAuth("over limit".into());
let forbidden = AccountError::PolicyDenied("vault outflow".into());
let unknown = AccountError::PolicyIndeterminate("clock unreadable".into());
assert!(matches!(escalatable, AccountError::RequireAuth(_)));
assert!(matches!(forbidden, AccountError::PolicyDenied(_)));
assert!(matches!(unknown, AccountError::PolicyIndeterminate(_)));
assert_eq!(
escalatable.to_string(),
"spend requires explicit authorization: over limit"
);
assert_eq!(
forbidden.to_string(),
"spend forbidden by custody policy: vault outflow"
);
assert_eq!(
unknown.to_string(),
"spend policy could not be evaluated: clock unreadable"
);
}
}