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

Commit

Permalink
add sub errors to SubSystemError
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Oct 21, 2020
1 parent 8ad2f36 commit d374799
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/subsystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ polkadot-statement-table = { path = "../../statement-table" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
smallvec = "1.4.1"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
thiserror = "1.0.21"

[dev-dependencies]
assert_matches = "1.3.0"
Expand Down
44 changes: 19 additions & 25 deletions node/subsystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,32 @@ pub enum FromOverseer<M> {
},
}


use thiserror::Error;
/// An error type that describes faults that may happen
///
/// These are:
/// * Channels being closed
/// * Subsystems dying when they are not expected to
/// * Subsystems not dying when they are told to die
/// * etc.
#[derive(Debug, PartialEq, Eq)]
pub struct SubsystemError;

impl From<mpsc::SendError> for SubsystemError {
fn from(_: mpsc::SendError) -> Self {
Self
}
}

impl From<oneshot::Canceled> for SubsystemError {
fn from(_: oneshot::Canceled) -> Self {
Self
}
}

impl From<futures::task::SpawnError> for SubsystemError {
fn from(_: futures::task::SpawnError) -> Self {
Self
}
}

impl From<std::convert::Infallible> for SubsystemError {
fn from(e: std::convert::Infallible) -> Self {
match e {}
}
#[derive(Error, Debug)]
pub enum SubsystemError {
/// A notification connection is no longer valid.
#[error(transparent)]
NotifyCancellation(#[from] oneshot::Canceled),

/// Queue does not accept another item.
#[error(transparent)]
QueueError(#[from] mpsc::SendError),

/// An attempt to spawn a futures task did not succeed.
#[error(transparent)]
TaskSpawn(#[from] futures::task::SpawnError),

/// An infallable error.
#[error(transparent)]
Infallible(#[from] std::convert::Infallible),
}

/// An asynchronous subsystem task..
Expand Down

0 comments on commit d374799

Please sign in to comment.