mnemonic_external/
error.rs

1#[cfg(feature = "std")]
2use std::string::String;
3
4#[cfg(not(feature = "std"))]
5use alloc::string::String;
6
7#[cfg(feature = "std")]
8use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
9
10#[cfg(not(feature = "std"))]
11use core::fmt::{Debug, Display, Formatter, Result as FmtResult};
12
13#[derive(Debug)]
14pub enum ErrorMnemonic {
15    DamagedWord,
16    InvalidChecksum,
17    InvalidEntropy,
18    InvalidWordNumber,
19    NoWord,
20    WordsNumber,
21}
22
23impl ErrorMnemonic {
24    fn error_text(&self) -> String {
25        match &self {
26            ErrorMnemonic::DamagedWord => String::from("Unable to extract a word from the word list."),
27            ErrorMnemonic::InvalidChecksum => String::from("Invalid text mnemonic: the checksum does not match."),
28            ErrorMnemonic::InvalidEntropy => String::from("Unable to calculate the mnemonic from entropy. Invalid entropy length."),
29            ErrorMnemonic::InvalidWordNumber => String::from("Ordinal number for word requested is higher than total number of words in the word list."),
30            ErrorMnemonic::NoWord => String::from("Requested word in not in the word list."),
31            ErrorMnemonic::WordsNumber => String::from("Invalid text mnemonic: unexpected number of words."),
32        }
33    }
34}
35
36impl Display for ErrorMnemonic {
37    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
38        write!(f, "{}", self.error_text())
39    }
40}
41
42#[cfg(feature = "std")]
43impl std::error::Error for ErrorMnemonic {}