Skip to content

Commit ad348d8

Browse files
authored
ready-cache: Properly expose error source (#467)
The `ready_cache::error::Failed` type does not actually expose its inner error type via `Error::source`. This change fixes this and improves debug formatting. This change adds a new constraint, ensuring that keys impl Debug in order for the `error::Failed` type to impl Debug/Error.
1 parent ab7518e commit ad348d8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tower/src/ready_cache/error.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ pub struct Failed<K>(pub K, pub crate::BoxError);
66

77
// === Failed ===
88

9-
impl<K> std::fmt::Debug for Failed<K> {
9+
impl<K: std::fmt::Debug> std::fmt::Debug for Failed<K> {
1010
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
11-
std::fmt::Debug::fmt(&self.1, f)
11+
f.debug_tuple("Failed")
12+
.field(&self.0)
13+
.field(&self.1)
14+
.finish()
1215
}
1316
}
1417

@@ -18,8 +21,8 @@ impl<K> std::fmt::Display for Failed<K> {
1821
}
1922
}
2023

21-
impl<K> std::error::Error for Failed<K> {
24+
impl<K: std::fmt::Debug> std::error::Error for Failed<K> {
2225
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23-
self.1.source()
26+
Some(&*self.1)
2427
}
2528
}

0 commit comments

Comments
 (0)