Skip to content

Commit 658d20c

Browse files
committed
Implement error source(), remove print in Debug
1 parent 11c6339 commit 658d20c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ pub enum Error {
111111
impl fmt::Debug for Error {
112112
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113113
match self {
114-
Error::Io(e) => write!(f, "{:?}", e),
115-
Error::Rpc(e) => write!(f, "{:?}", e),
114+
Error::Io(_) => write!(f, "io::Error"),
115+
Error::Rpc(_) => write!(f, "bitcoin_rpc::Error"),
116116
Error::NoFeature => write!(f, "Called a method requiring a feature to be set, but it's not"),
117117
Error::NoEnvVar => write!(f, "Called a method requiring env var `BITCOIND_EXE` to be set, but it's not"),
118118
Error::NoBitcoindExecutableFound => write!(f, "`bitcoind` executable is required, provide it with one of the following: set env var `BITCOIND_EXE` or use a feature like \"22_0\" or have `bitcoind` executable in the `PATH`"),
@@ -130,7 +130,15 @@ impl std::fmt::Display for Error {
130130
}
131131
}
132132

133-
impl std::error::Error for Error {}
133+
impl std::error::Error for Error {
134+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
135+
match self {
136+
Error::Io(e) => Some(e),
137+
Error::Rpc(e) => Some(e),
138+
_ => None,
139+
}
140+
}
141+
}
134142

135143
const LOCAL_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
136144

0 commit comments

Comments
 (0)