forked from infincia/bip39-rs
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from failure to anyhow+thiserror (#24)
* Switch from failure to anyhow+thiserror * Missing NL at EOF
- Loading branch information
1 parent
780e3a4
commit e410aca
Showing
6 changed files
with
33 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
use crate::mnemonic_type::MnemonicType; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Fail)] | ||
#[derive(Debug, Error)] | ||
pub enum ErrorKind { | ||
#[fail(display = "invalid checksum")] | ||
#[error("invalid checksum")] | ||
InvalidChecksum, | ||
#[fail(display = "invalid word in phrase")] | ||
#[error("invalid word in phrase")] | ||
InvalidWord, | ||
#[fail(display = "invalid keysize: {}", _0)] | ||
#[error("invalid keysize: {0}")] | ||
InvalidKeysize(usize), | ||
#[fail(display = "invalid number of words in phrase: {}", _0)] | ||
#[error("invalid number of words in phrase: {0}")] | ||
InvalidWordLength(usize), | ||
#[fail( | ||
display = "invalid entropy length {}bits for mnemonic type {:?}", | ||
_0, _1 | ||
)] | ||
#[error("invalid entropy length {0}bits for mnemonic type {1:?}")] | ||
InvalidEntropyLength(usize, MnemonicType), | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn prints_correctly() { | ||
assert_eq!( | ||
format!("{}", ErrorKind::InvalidChecksum), | ||
"invalid checksum", | ||
); | ||
assert_eq!( | ||
format!("{}", ErrorKind::InvalidKeysize(42)), | ||
"invalid keysize: 42", | ||
); | ||
assert_eq!( | ||
format!("{}", ErrorKind::InvalidEntropyLength(42, MnemonicType::Words12)), | ||
"invalid entropy length 42bits for mnemonic type Words12", | ||
); | ||
} | ||
} |
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