Skip to content

Commit 76cf6dd

Browse files
committed
feat(error): change Display for Error to only print top error
hyper's `Error` used to print the error source automatically, preferring to provide a better default for users who do not know about `Report`. But, to fit better with the wider ecosystem, this changes the format to only print the hyper `Error` itself, and not its source. Closes #2844 BREAKING CHANGE: The format no longer prints the error chain. Be sure to check if you are logging errors directly. The `Error::message()` method is removed, it is no longer needed. The `Error::into_cause()` method is removed.
1 parent 7f0c7ba commit 76cf6dd

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/error.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ pub type Result<T> = std::result::Result<T, Error>;
88
type Cause = Box<dyn StdError + Send + Sync>;
99

1010
/// Represents errors that can occur handling HTTP streams.
11+
///
12+
/// # Formatting
13+
///
14+
/// The `Display` implementation of this type will only print the details of
15+
/// this level of error, even though it may have been caused by another error
16+
/// and contain that error in its source. To print all the relevant
17+
/// information, including the source chain, using something like
18+
/// `std::error::Report`, or equivalent 3rd party types.
19+
///
20+
/// The contents of the formatted error message of this specific `Error` type
21+
/// is unspecified. **You must not depend on it.** The wording and details may
22+
/// change in any version, with the goal of improving error messages.
1123
pub struct Error {
1224
inner: Box<ErrorImpl>,
1325
}
@@ -173,11 +185,6 @@ impl Error {
173185
self.find_source::<TimedOut>().is_some()
174186
}
175187

176-
/// Consumes the error, returning its cause.
177-
pub fn into_cause(self) -> Option<Box<dyn StdError + Send + Sync>> {
178-
self.inner.cause
179-
}
180-
181188
pub(super) fn new(kind: Kind) -> Error {
182189
Error {
183190
inner: Box::new(ErrorImpl { kind, cause: None }),
@@ -332,11 +339,6 @@ impl Error {
332339
}
333340
}
334341

335-
/// The error's standalone message, without the message from the source.
336-
pub fn message(&self) -> impl fmt::Display + '_ {
337-
self.description()
338-
}
339-
340342
fn description(&self) -> &str {
341343
match self.inner.kind {
342344
Kind::Parse(Parse::Method) => "invalid HTTP method parsed",
@@ -420,11 +422,7 @@ impl fmt::Debug for Error {
420422

421423
impl fmt::Display for Error {
422424
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
423-
if let Some(ref cause) = self.inner.cause {
424-
write!(f, "{}: {}", self.description(), cause)
425-
} else {
426-
f.write_str(self.description())
427-
}
425+
f.write_str(self.description())
428426
}
429427
}
430428

tests/client.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2318,10 +2318,6 @@ mod conn {
23182318
let error = client.send_request(req).await.unwrap_err();
23192319

23202320
assert!(error.is_user());
2321-
assert_eq!(
2322-
error.to_string(),
2323-
"dispatch task is gone: user code panicked"
2324-
);
23252321
}
23262322

23272323
async fn drain_til_eof<T: tokio::io::AsyncRead + Unpin>(mut sock: T) -> io::Result<()> {

0 commit comments

Comments
 (0)