Skip to content

Commit

Permalink
refactor: mark errors as non_exhaustive
Browse files Browse the repository at this point in the history
It should allow to introduce new error variants without breaking changes

BREAKING_CHANGE: requires to specify irrefutable pattern for pattern matching in order to exhaust any possible variants
  • Loading branch information
meskill committed Jul 3, 2022
1 parent 02ebc48 commit 5064098
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/sdk/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ use custom_error::custom_error;

custom_error! {
/// Errors generated by the MysticLight SDK, see [SDK docs](https://www.msi.com/Landing/mystic-light-rgb-gaming-pc/download)
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",
#[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
pub UsageError
/// Tried to set style that is not supported by current device
NotSupportedStyle{style: String, supported_styles: String} = "{style} is not in the supported style list: {supported_styles}"
/// 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}"
}

custom_error! {
/// CommonError that may happen during usage of this library
/// CommonError that may happen during usage of this library
#[non_exhaustive]
pub CommonError
SdkError{source: MysticLightSDKError} = "SdkError({source})",
LibraryError{source: LibLoadingError} = "LibraryError({source})",
Expand Down

0 comments on commit 5064098

Please sign in to comment.