Skip to content

Commit dbc2272

Browse files
authored
Merge pull request rust-bitcoin#113 from nyonson/fix/error-context
2 parents eee5127 + 3aa0912 commit dbc2272

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

protocol/src/lib.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,20 @@ impl fmt::Display for Error {
130130
}
131131

132132
#[cfg(feature = "std")]
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::CiphertextTooSmall => None,
137+
Error::BufferTooSmall { .. } => None,
138+
Error::NoGarbageTerminator => None,
139+
Error::HandshakeOutOfOrder => None,
140+
Error::V1Protocol => None,
141+
Error::SecretGeneration(e) => Some(e),
142+
Error::Decryption(e) => Some(e),
143+
Error::TooMuchGarbage => None,
144+
}
145+
}
146+
}
134147

135148
impl From<fschacha20poly1305::Error> for Error {
136149
fn from(e: fschacha20poly1305::Error) -> Self {
@@ -1056,7 +1069,14 @@ impl From<Error> for ProtocolError {
10561069
}
10571070

10581071
#[cfg(feature = "std")]
1059-
impl std::error::Error for ProtocolError {}
1072+
impl std::error::Error for ProtocolError {
1073+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1074+
match self {
1075+
ProtocolError::Io(e, _) => Some(e),
1076+
ProtocolError::Internal(e) => Some(e),
1077+
}
1078+
}
1079+
}
10601080

10611081
#[cfg(feature = "std")]
10621082
impl fmt::Display for ProtocolError {

proxy/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ impl fmt::Display for Error {
4949
}
5050
}
5151

52-
impl std::error::Error for Error {}
52+
impl std::error::Error for Error {
53+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54+
match self {
55+
Error::WrongNetwork => None,
56+
Error::WrongCommand => None,
57+
Error::Serde => None,
58+
Error::Io(e) => Some(e),
59+
Error::Protocol(e) => Some(e),
60+
}
61+
}
62+
}
5363

5464
impl From<bip324::ProtocolError> for Error {
5565
fn from(e: bip324::ProtocolError) -> Self {

0 commit comments

Comments
 (0)