Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement std::error::Error for InboundFailure and OutboundFailure #2033

Merged
merged 4 commits into from
Apr 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ pub enum OutboundFailure {
UnsupportedProtocols,
}

impl fmt::Display for OutboundFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OutboundFailure::DialFailure => write!(f, "failed to dial the requested peer"),
OutboundFailure::Timeout => write!(f, "timeout while waiting for a response"),
OutboundFailure::ConnectionClosed => write!(f, "connection was closed before a response was received"),
OutboundFailure::UnsupportedProtocols => write!(f, "the remote supports none of the requested protocols")
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl std::error::Error for OutboundFailure {}

/// Possible failures occurring in the context of receiving an
/// inbound request and sending a response.
#[derive(Debug, Clone, PartialEq)]
Expand All @@ -201,6 +214,19 @@ pub enum InboundFailure {
ResponseOmission,
}

impl fmt::Display for InboundFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InboundFailure::Timeout => write!(f, "timeout while receiving request or sending response"),
InboundFailure::ConnectionClosed => write!(f, "connection was closed before a response could be sent"),
InboundFailure::UnsupportedProtocols => write!(f, "the local peer supports none of the protocols requested by the remote"),
InboundFailure::ResponseOmission => write!(f, "the response channel was dropped without sending a response to the remote")
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl std::error::Error for InboundFailure {}

/// A channel for sending a response to an inbound request.
///
/// See [`RequestResponse::send_response`].
Expand Down