Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl compare for FabricErrorCode #110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/libs/core/src/error/errorcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const E_NOT_FOUND: FABRIC_ERROR_CODE =
macro_rules! define_fabric_error_code{
($( $code1:ident ),* ,($lit:literal), $( $code:ident ),*) =>{
#[allow(non_camel_case_types)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
#[repr(i32)]
pub enum FabricErrorCode {
// Define windows error codes for SF
Expand Down
9 changes: 9 additions & 0 deletions crates/libs/core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ impl FabricError {
pub fn new(code: HRESULT) -> Self {
Self(code)
}

/// Convert to fabric error code if possible.
pub fn try_as_fabric_error_code(&self) -> Result<FabricErrorCode, &str> {
FabricErrorCode::try_from(FABRIC_ERROR_CODE(self.0 .0))
}
}

impl From<HRESULT> for FabricError {
Expand Down Expand Up @@ -104,6 +109,10 @@ mod test {
);
let e = crate::Error::from(fe.clone());
assert_eq!(e.code(), fe.into());
let ec = FabricError::from(e)
.try_as_fabric_error_code()
.expect("unknown code");
assert_eq!(ec, FabricErrorCode::FABRIC_E_CODE_PACKAGE_NOT_FOUND);
}

#[test]
Expand Down
Loading