sc_mixnet/error.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use codec::{Decode, Encode};
20use mixnet::core::PostErr;
21
22/// Error handling a request. Sent in replies over the mixnet.
23#[derive(Debug, thiserror::Error, Decode, Encode)]
24pub enum RemoteErr {
25 /// An error that doesn't map to any of the other variants.
26 #[error("{0}")]
27 Other(String),
28 /// Failed to decode the request.
29 #[error("Failed to decode the request: {0}")]
30 Decode(String),
31}
32
33/// Mixnet error.
34#[derive(Debug, thiserror::Error)]
35pub enum Error {
36 /// Failed to communicate with the mixnet service. Possibly it panicked. The node probably
37 /// needs to be restarted.
38 #[error(
39 "Failed to communicate with the mixnet service; the node probably needs to be restarted"
40 )]
41 ServiceUnavailable,
42 /// Did not receive a reply after the configured number of attempts.
43 #[error("Did not receive a reply from the mixnet after the configured number of attempts")]
44 NoReply,
45 /// Received a malformed reply.
46 #[error("Received a malformed reply from the mixnet")]
47 BadReply,
48 /// Failed to post the request to the mixnet. Note that some [`PostErr`] variants, eg
49 /// [`PostErr::NotEnoughSpaceInQueue`], are handled internally and will never be returned from
50 /// the top-level API.
51 #[error("Failed to post the request to the mixnet: {0}")]
52 Post(#[from] PostErr),
53 /// Error reported by destination mixnode.
54 #[error("Error reported by the destination mixnode: {0}")]
55 Remote(#[from] RemoteErr),
56}