use std::clone::Clone; use std::sync::PoisonError; use custom_error::custom_error; use libloading::Error as LibLoadingError; use super::types::{BrightLevel, SpeedLevel}; custom_error! { /// Errors generated by the MysticLight SDK, see [SDK docs](https://www.msi.com/Landing/mystic-light-rgb-gaming-pc/download) #[non_exhaustive] pub MysticLightSDKError Generic = "Generic error", /// This error will raise in case of insufficient rights as well (run as an administrator) Timeout = "Request is timeout", NotImplemented = "MSI Application not found or installed version not supported", NotInitialized = "MSI Application was not initialized", InvalidArgument = "The parameter value is not valid", DeviceNotFound = "The device not found", NotSupported = "Requested feature is not supported in the selected LED", Unknown = "Unknown error", } custom_error! { /// Errors for bad sdk usage #[non_exhaustive] pub UsageError /// Tried to set style that is not supported by current device #[non_exhaustive] NotSupportedStyle{style: String, supported_styles: String} = "{style} is not in the supported style list: {supported_styles}", /// Tried to set brightness level higher that supported #[non_exhaustive] ExcessBrightLevel{level: BrightLevel, max_level: BrightLevel} = "Passed bright level={level} exceeds supported {max_level}", /// Tried to set speed level higher that supported #[non_exhaustive] ExcessSpeedLevel{level: SpeedLevel, max_level: SpeedLevel} = "Passed speed level={level} exceeds supported {max_level}", } custom_error! { /// Errors with multithreading #[derive(Clone)] #[non_exhaustive] pub SyncError Poison = "Shared object (Mutex or RwLock) is poisoned" } impl From> for SyncError { fn from(_: PoisonError) -> Self { Self::Poison } } custom_error! { /// CommonError that may happen during usage of this library #[non_exhaustive] pub CommonError SdkError{source: MysticLightSDKError} = "SdkError({source})", LibraryError{source: LibLoadingError} = "LibraryError({source})", UsageError{source: UsageError} = "UsageError({source})", SyncError{source: SyncError} = "SyncError({source})", } impl From> for CommonError { fn from(error: PoisonError) -> Self { Self::SyncError { source: error.into(), } } }