Skip to main content

kobe_core/
error.rs

1//! Error types for core wallet operations.
2
3use core::fmt;
4
5/// Errors that can occur during wallet operations.
6#[derive(Debug)]
7pub enum Error {
8    /// Invalid mnemonic phrase.
9    Mnemonic(bip39::Error),
10    /// Invalid word count for mnemonic.
11    InvalidWordCount(usize),
12}
13
14impl fmt::Display for Error {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::Mnemonic(e) => write!(f, "mnemonic error: {e}"),
18            Self::InvalidWordCount(n) => {
19                write!(f, "invalid word count {n}, must be 12, 15, 18, 21, or 24")
20            }
21        }
22    }
23}
24
25#[cfg(feature = "std")]
26impl std::error::Error for Error {
27    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28        match self {
29            Self::Mnemonic(e) => Some(e),
30            Self::InvalidWordCount(_) => None,
31        }
32    }
33}
34
35impl From<bip39::Error> for Error {
36    fn from(err: bip39::Error) -> Self {
37        Self::Mnemonic(err)
38    }
39}