Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit d374799

Browse files
committed
add sub errors to SubSystemError
1 parent 8ad2f36 commit d374799

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/subsystem/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ polkadot-statement-table = { path = "../../statement-table" }
2121
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
2222
smallvec = "1.4.1"
2323
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
24+
thiserror = "1.0.21"
2425

2526
[dev-dependencies]
2627
assert_matches = "1.3.0"

node/subsystem/src/lib.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,32 @@ pub enum FromOverseer<M> {
105105
},
106106
}
107107

108+
109+
use thiserror::Error;
108110
/// An error type that describes faults that may happen
109111
///
110112
/// These are:
111113
/// * Channels being closed
112114
/// * Subsystems dying when they are not expected to
113115
/// * Subsystems not dying when they are told to die
114116
/// * etc.
115-
#[derive(Debug, PartialEq, Eq)]
116-
pub struct SubsystemError;
117-
118-
impl From<mpsc::SendError> for SubsystemError {
119-
fn from(_: mpsc::SendError) -> Self {
120-
Self
121-
}
122-
}
123-
124-
impl From<oneshot::Canceled> for SubsystemError {
125-
fn from(_: oneshot::Canceled) -> Self {
126-
Self
127-
}
128-
}
129-
130-
impl From<futures::task::SpawnError> for SubsystemError {
131-
fn from(_: futures::task::SpawnError) -> Self {
132-
Self
133-
}
134-
}
135-
136-
impl From<std::convert::Infallible> for SubsystemError {
137-
fn from(e: std::convert::Infallible) -> Self {
138-
match e {}
139-
}
117+
#[derive(Error, Debug)]
118+
pub enum SubsystemError {
119+
/// A notification connection is no longer valid.
120+
#[error(transparent)]
121+
NotifyCancellation(#[from] oneshot::Canceled),
122+
123+
/// Queue does not accept another item.
124+
#[error(transparent)]
125+
QueueError(#[from] mpsc::SendError),
126+
127+
/// An attempt to spawn a futures task did not succeed.
128+
#[error(transparent)]
129+
TaskSpawn(#[from] futures::task::SpawnError),
130+
131+
/// An infallable error.
132+
#[error(transparent)]
133+
Infallible(#[from] std::convert::Infallible),
140134
}
141135

142136
/// An asynchronous subsystem task..

0 commit comments

Comments
 (0)