use std::fmt::{Display, Formatter};
pub type ContractResult<T> = Result<T, ContractError>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ContractError {
Empty {
field: &'static str,
},
TooLong {
field: &'static str,
max_bytes: usize,
},
InvalidIdentifier {
field: &'static str,
},
InvalidValue {
field: &'static str,
reason: &'static str,
},
Duplicate {
field: &'static str,
value: String,
},
SecretValue {
field: String,
},
LocalPath {
field: String,
},
}
impl Display for ContractError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Empty { field } => write!(formatter, "{field} must not be empty"),
Self::TooLong { field, max_bytes } => {
write!(formatter, "{field} must not exceed {max_bytes} bytes")
}
Self::InvalidIdentifier { field } => {
write!(formatter, "{field} is not a valid distributed identifier")
}
Self::InvalidValue { field, reason } => write!(formatter, "{field}: {reason}"),
Self::Duplicate { field, value } => write!(formatter, "duplicate {field}: {value}"),
Self::SecretValue { field } => {
write!(formatter, "{field} must use a secret reference")
}
Self::LocalPath { field } => {
write!(formatter, "{field} must be declared by the deployment")
}
}
}
}
impl std::error::Error for ContractError {}