|
4 | 4 | //
|
5 | 5 | // Copyright (c) DUSK NETWORK. All rights reserved.
|
6 | 6 |
|
7 |
| -use std::{fmt, io}; |
| 7 | +use std::io; |
8 | 8 |
|
9 | 9 | use dusk_bytes::Serializable;
|
10 |
| -use dusk_core::{ |
11 |
| - signatures::bls::PublicKey as BlsPublicKey, transfer::phoenix::CoreError, |
12 |
| - BlsScalar, Error as ExecErr, |
13 |
| -}; |
| 10 | +use dusk_core::signatures::bls::PublicKey as BlsPublicKey; |
| 11 | +use dusk_core::transfer::phoenix::CoreError as PhoenixError; |
| 12 | +use dusk_core::{BlsScalar, Error as ExecErr}; |
14 | 13 | use dusk_vm::Error as VMError;
|
15 | 14 |
|
16 |
| -#[derive(Debug)] |
| 15 | +#[derive(Debug, thiserror::Error)] |
17 | 16 | pub enum Error {
|
18 |
| - /// Failed to register a backend for persistence |
19 |
| - BackendRegistrationFailed, |
20 |
| - /// Failed to restore a network state from disk |
21 |
| - RestoreFailed, |
22 |
| - /// Proof verification failure |
23 |
| - ProofVerification, |
24 | 17 | /// Out of gas in block execution
|
| 18 | + #[error("Out of gas")] |
25 | 19 | OutOfGas,
|
26 | 20 | /// Repeated nullifier in transaction verification
|
| 21 | + #[error("Nullifiers already spent: {0:?}")] |
27 | 22 | RepeatingNullifiers(Vec<BlsScalar>),
|
28 | 23 | /// Repeated nullifier in the same transaction
|
| 24 | + #[error("Double nullifiers")] |
29 | 25 | DoubleNullifiers,
|
30 | 26 | /// Repeating a nonce that has already been used
|
| 27 | + #[error("Nonce repeat: {} {1}", bs58::encode(.0.to_bytes()).into_string())] |
31 | 28 | RepeatingNonce(Box<BlsPublicKey>, u64),
|
32 | 29 | /// Wrong inputs and/or outputs in the transaction verification
|
| 30 | + #[error("Expected: 0 < (inputs: {0}) < 5, 0 ≤ (outputs: {1}) < 3")] |
33 | 31 | InvalidCircuitArguments(usize, usize),
|
34 |
| - /// Failed to build a Rusk instance |
35 |
| - BuilderInvalidState, |
36 | 32 | /// Failed to fetch opening
|
| 33 | + #[error("Failed to fetch opening of position {0}")] |
37 | 34 | OpeningPositionNotFound(u64),
|
38 |
| - /// Failed to fetch opening due to undefined Note |
39 |
| - OpeningNoteUndefined(u64), |
40 | 35 | /// Bytes Serialization Errors
|
| 36 | + #[error("Serialization Error: {0:?}")] |
41 | 37 | Serialization(dusk_bytes::Error),
|
42 | 38 | /// Originating from transaction-creation
|
| 39 | + #[error("Transaction Error: {0}")] |
43 | 40 | Transaction(ExecErr),
|
44 | 41 | /// Originating from Phoenix.
|
45 |
| - Phoenix(CoreError), |
| 42 | + #[error("Phoenix Error: {0}")] |
| 43 | + Phoenix(PhoenixError), |
46 | 44 | /// Piecrust VM internal Errors
|
47 |
| - Vm(VMError), |
| 45 | + #[error("VM Error: {0}")] |
| 46 | + Vm(#[from] VMError), |
48 | 47 | /// IO Errors
|
49 |
| - Io(io::Error), |
| 48 | + #[error("IO Error: {0}")] |
| 49 | + Io(#[from] io::Error), |
50 | 50 | /// Other
|
51 |
| - Other(Box<dyn std::error::Error>), |
| 51 | + #[error("Other Error: {0}")] |
| 52 | + Other(#[from] Box<dyn std::error::Error>), |
52 | 53 | /// Commit not found amongst existing commits
|
| 54 | + #[error("Commit not found, id = {}", hex::encode(.0))] |
53 | 55 | CommitNotFound([u8; 32]),
|
54 | 56 | /// Invalid credits count
|
| 57 | + #[error("Invalid credits: H= {0}, credits= {1}")] |
55 | 58 | InvalidCreditsCount(u64, usize),
|
56 | 59 | /// Memo too large
|
| 60 | + #[error("The memo size {0} is too large")] |
57 | 61 | MemoTooLarge(usize),
|
58 | 62 | /// Blob related errors
|
| 63 | + #[error("Blob error: {0}")] |
59 | 64 | Blob(String),
|
60 | 65 | }
|
61 | 66 |
|
62 |
| -impl std::error::Error for Error {} |
63 |
| - |
64 |
| -impl From<Box<dyn std::error::Error>> for Error { |
65 |
| - fn from(err: Box<dyn std::error::Error>) -> Self { |
66 |
| - Error::Other(err) |
67 |
| - } |
68 |
| -} |
69 |
| - |
70 |
| -impl From<VMError> for Error { |
71 |
| - fn from(err: VMError) -> Self { |
72 |
| - Error::Vm(err) |
73 |
| - } |
74 |
| -} |
75 |
| - |
76 | 67 | impl From<dusk_core::Error> for Error {
|
77 | 68 | fn from(err: ExecErr) -> Self {
|
78 | 69 | match err {
|
@@ -117,70 +108,8 @@ impl From<dusk_bytes::Error> for Error {
|
117 | 108 | }
|
118 | 109 | }
|
119 | 110 |
|
120 |
| -impl From<CoreError> for Error { |
121 |
| - fn from(pe: CoreError) -> Self { |
| 111 | +impl From<PhoenixError> for Error { |
| 112 | + fn from(pe: PhoenixError) -> Self { |
122 | 113 | Self::Phoenix(pe)
|
123 | 114 | }
|
124 | 115 | }
|
125 |
| - |
126 |
| -impl From<io::Error> for Error { |
127 |
| - fn from(err: io::Error) -> Self { |
128 |
| - Error::Io(err) |
129 |
| - } |
130 |
| -} |
131 |
| - |
132 |
| -impl fmt::Display for Error { |
133 |
| - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
134 |
| - match self { |
135 |
| - Error::BackendRegistrationFailed => { |
136 |
| - write!(f, "Failed to register a backend for persistence") |
137 |
| - } |
138 |
| - Error::RestoreFailed => { |
139 |
| - write!(f, "Failed to restore a network state") |
140 |
| - } |
141 |
| - Error::BuilderInvalidState => { |
142 |
| - write!(f, "Failed to build a Rusk instance") |
143 |
| - } |
144 |
| - Error::OpeningPositionNotFound(pos) => { |
145 |
| - write!(f, "Failed to fetch opening of position {pos}") |
146 |
| - } |
147 |
| - Error::OpeningNoteUndefined(pos) => { |
148 |
| - write!(f, "Note {pos} not found, opening of position") |
149 |
| - } |
150 |
| - Error::Serialization(err) => { |
151 |
| - write!(f, "Serialization Error: {err:?}") |
152 |
| - } |
153 |
| - Error::Vm(err) => write!(f, "VM Error: {err}"), |
154 |
| - Error::Io(err) => write!(f, "IO Error: {err}"), |
155 |
| - Error::Transaction(err) => write!(f, "Transaction Error: {err}"), |
156 |
| - Error::Phoenix(err) => write!(f, "Phoenix error: {err}"), |
157 |
| - Error::Other(err) => write!(f, "Other error: {err}"), |
158 |
| - Error::ProofVerification => write!(f, "Proof verification failure"), |
159 |
| - Error::OutOfGas => write!(f, "Out of gas"), |
160 |
| - Error::RepeatingNullifiers(n) => { |
161 |
| - write!(f, "Nullifiers already spent: {n:?}") |
162 |
| - } |
163 |
| - Error::DoubleNullifiers => write!(f, "Double nullifiers"), |
164 |
| - Error::RepeatingNonce(account, nonce) => { |
165 |
| - let encoded_account = |
166 |
| - bs58::encode(&account.to_bytes()).into_string(); |
167 |
| - write!(f, "Nonce repeat: {encoded_account} {nonce}") |
168 |
| - } |
169 |
| - Error::InvalidCircuitArguments(inputs_len, outputs_len) => { |
170 |
| - write!(f,"Expected: 0 < (inputs: {inputs_len}) < 5, 0 ≤ (outputs: {outputs_len}) < 3") |
171 |
| - } |
172 |
| - Error::CommitNotFound(commit_id) => { |
173 |
| - write!(f, "Commit not found, id = {}", hex::encode(commit_id),) |
174 |
| - } |
175 |
| - Error::InvalidCreditsCount(height, credits) => { |
176 |
| - write!(f, "Invalid credits: H= {height}, credits= {credits}",) |
177 |
| - } |
178 |
| - Error::MemoTooLarge(size) => { |
179 |
| - write!(f, "The memo size {size} is too large") |
180 |
| - } |
181 |
| - Error::Blob(e) => { |
182 |
| - write!(f, "Blob error: {e}") |
183 |
| - } |
184 |
| - } |
185 |
| - } |
186 |
| -} |
0 commit comments