-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solana-ibc: introduce error module; move Error enum there (#87)
The module is tiny at the moment but with time more variants will be added to the variant which would otherwise live in the lib.rs file making it grow in size even more.
- Loading branch information
Showing
6 changed files
with
49 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Error returned when handling a request. | ||
// Note: When changing variants in the enum, try to preserve indexes of each | ||
// variant. The position is translated into error code returned by Anchor and | ||
// keeping them consistent makes things easier. | ||
#[derive(strum::EnumDiscriminants, strum::IntoStaticStr)] | ||
#[strum_discriminants(repr(u32))] | ||
#[allow(clippy::enum_variant_names)] | ||
pub(crate) enum Error { | ||
/// Error handling an IBC request. | ||
RouterError(ibc::core::RouterError), | ||
} | ||
|
||
impl Error { | ||
pub fn name(&self) -> String { <&'static str>::from(self).into() } | ||
} | ||
|
||
impl core::fmt::Display for Error { | ||
fn fmt(&self, fmtr: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::RouterError(err) => err.fmt(fmtr), | ||
} | ||
} | ||
} | ||
|
||
impl From<Error> for u32 { | ||
fn from(err: Error) -> u32 { | ||
let code = ErrorDiscriminants::from(err) as u32; | ||
anchor_lang::error::ERROR_CODE_OFFSET + code | ||
} | ||
} | ||
|
||
impl From<&Error> for u32 { | ||
fn from(err: &Error) -> u32 { | ||
let code = ErrorDiscriminants::from(err) as u32; | ||
anchor_lang::error::ERROR_CODE_OFFSET + code | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters