Skip to main content

soil_network/mixnet/
error.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7use codec::{Decode, Encode};
8use mixnet::core::PostErr;
9
10/// Error handling a request. Sent in replies over the mixnet.
11#[derive(Debug, thiserror::Error, Decode, Encode)]
12pub enum RemoteErr {
13	/// An error that doesn't map to any of the other variants.
14	#[error("{0}")]
15	Other(String),
16	/// Failed to decode the request.
17	#[error("Failed to decode the request: {0}")]
18	Decode(String),
19}
20
21/// Mixnet error.
22#[derive(Debug, thiserror::Error)]
23pub enum Error {
24	/// Failed to communicate with the mixnet service. Possibly it panicked. The node probably
25	/// needs to be restarted.
26	#[error(
27		"Failed to communicate with the mixnet service; the node probably needs to be restarted"
28	)]
29	ServiceUnavailable,
30	/// Did not receive a reply after the configured number of attempts.
31	#[error("Did not receive a reply from the mixnet after the configured number of attempts")]
32	NoReply,
33	/// Received a malformed reply.
34	#[error("Received a malformed reply from the mixnet")]
35	BadReply,
36	/// Failed to post the request to the mixnet. Note that some [`PostErr`] variants, eg
37	/// [`PostErr::NotEnoughSpaceInQueue`], are handled internally and will never be returned from
38	/// the top-level API.
39	#[error("Failed to post the request to the mixnet: {0}")]
40	Post(#[from] PostErr),
41	/// Error reported by destination mixnode.
42	#[error("Error reported by the destination mixnode: {0}")]
43	Remote(#[from] RemoteErr),
44}