Skip to content

feat(client/dispatch): TrySendError<T>: std::error::Error #3922

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::error::Error as StdError;
use std::fmt;
use std::task::{Context, Poll};
#[cfg(feature = "http2")]
use std::{future::Future, pin::Pin};
Expand Down Expand Up @@ -323,6 +325,22 @@ impl<T> TrySendError<T> {
}
}

impl<T> fmt::Display for TrySendError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { error, message: _ } = self;
write!(f, "{}", error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds of the guidelines that an error should either be in the Display, or the source, but not both...

I do think a message like error trying to send request before it was consumed is less useful...

}
}

impl<T> StdError for TrySendError<T>
where
T: std::fmt::Debug,
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}

#[cfg(feature = "http2")]
pin_project! {
pub struct SendWhen<B>
Expand Down
Loading