1use alloc::string::String;
10use core::fmt;
11
12#[derive(Debug, Clone, PartialEq)]
14pub enum Error {
15 InsufficientBalance,
17 Replay,
19 PhoenixOwnership,
21 PhoenixCircuit(String),
23 PhoenixProver(String),
25 InvalidData,
27 BadLength(usize, usize),
29 InvalidChar(char, usize),
31 Rkyv(String),
33 MemoTooLarge(usize),
38}
39
40impl fmt::Display for Error {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 write!(f, "Dusk-Core Error: {:?}", &self)
43 }
44}
45
46impl From<phoenix_core::Error> for Error {
47 fn from(core_error: phoenix_core::Error) -> Self {
48 #[allow(clippy::match_same_arms)]
49 match core_error {
50 phoenix_core::Error::InvalidNoteType(_) => Self::InvalidData,
51 phoenix_core::Error::MissingViewKey => Self::PhoenixOwnership,
52 phoenix_core::Error::InvalidEncryption => Self::PhoenixOwnership,
53 phoenix_core::Error::InvalidData => Self::InvalidData,
54 phoenix_core::Error::BadLength(found, expected) => {
55 Self::BadLength(found, expected)
56 }
57 phoenix_core::Error::InvalidChar(ch, index) => {
58 Self::InvalidChar(ch, index)
59 }
60 }
61 }
62}
63
64impl From<dusk_bytes::Error> for Error {
65 fn from(bytes_error: dusk_bytes::Error) -> Self {
66 match bytes_error {
67 dusk_bytes::Error::InvalidData => Self::InvalidData,
68 dusk_bytes::Error::BadLength { found, expected } => {
69 Self::BadLength(found, expected)
70 }
71 dusk_bytes::Error::InvalidChar { ch, index } => {
72 Self::InvalidChar(ch, index)
73 }
74 }
75 }
76}