use ink::prelude::string::String; use core::fmt; #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum PSP34Error { /// Custom error type for cases if writer of traits added own restrictions Custom(String), /// Returned if owner approves self SelfApprove, /// Returned if the caller doesn't have allowance for transferring. NotApproved, /// Returned if the owner already own the token. TokenExists, /// Returned if the token doesn't exist TokenNotExists, /// Returned if safe transfer check fails SafeTransferCheckFailed(String), } /// Errors related to ownership operations. /// /// This enum is used for managing errors that occur in ownership-related /// functionalities. #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum OwnableError { NotAnOwner } impl core::fmt::Display for OwnableError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:?}", self) } } #[cfg(test)] mod tests { #[test] fn test_display_ownable_error() { let error = crate::errors::OwnableError::NotAnOwner; assert_eq!(format!("{}", error), "NotAnOwner"); } }