p2p: Add explicit None return impl for std::error::Error
What changed, and why it matters
This commit is a straightforward code cleanup. It rewrites several Rust error-type definitions so they explicitly state that they have no underlying 'cause' error, instead of relying on the programming language's automatic default. The behavior of the program is unchanged, and there is no security issue.
No action required; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch replaces blanket impl std::error::Error for ... {} implementations with explicit source() methods that return None for every enum variant. Because the default method provided by std::error::Error already returns None, this is a purely cosmetic/documentation change with no functional or security impact.
Changed components
p2p/src/address.rsp2p/src/message.rsInspect captured patch +52 / −5
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index e8947d24..426a8711 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -968,7 +968,17 @@ impl fmt::Display for UnroutableAddressError {
}
#[cfg(feature = "std")]
-impl std::error::Error for UnroutableAddressError {}
+impl std::error::Error for UnroutableAddressError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::TorV2 => None,
+ Self::TorV3 => None,
+ Self::I2p => None,
+ Self::Cjdns => None,
+ Self::Unknown => None,
+ }
+ }
+}
/// Error types for [`AddrV2`] to [`IpAddr`] conversion.
#[derive(Debug, PartialEq, Eq)]
@@ -994,7 +1004,16 @@ impl fmt::Display for AddrV2ToIpAddrError {
}
}
-impl std::error::Error for AddrV2ToIpAddrError {}
+impl std::error::Error for AddrV2ToIpAddrError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::TorV3 => None,
+ Self::I2p => None,
+ Self::Cjdns => None,
+ Self::Unknown => None,
+ }
+ }
+}
/// Error types for [`AddrV2`] to [`Ipv4Addr`] conversion.
#[derive(Debug, PartialEq, Eq)]
@@ -1023,7 +1042,17 @@ impl fmt::Display for AddrV2ToIpv4AddrError {
}
}
-impl std::error::Error for AddrV2ToIpv4AddrError {}
+impl std::error::Error for AddrV2ToIpv4AddrError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::Ipv6 => None,
+ Self::TorV3 => None,
+ Self::I2p => None,
+ Self::Cjdns => None,
+ Self::Unknown => None,
+ }
+ }
+}
/// Error types for [`AddrV2`] to [`Ipv6Addr`] conversion.
#[derive(Debug, PartialEq, Eq)]
@@ -1052,7 +1081,17 @@ impl fmt::Display for AddrV2ToIpv6AddrError {
}
}
-impl std::error::Error for AddrV2ToIpv6AddrError {}
+impl std::error::Error for AddrV2ToIpv6AddrError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::Ipv4 => None,
+ Self::TorV3 => None,
+ Self::I2p => None,
+ Self::Cjdns => None,
+ Self::Unknown => None,
+ }
+ }
+}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for Address {
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index 31818099..96b61d23 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -1667,7 +1667,15 @@ impl fmt::Display for V1NetworkMessageDecoderError {
}
#[cfg(feature = "std")]
-impl std::error::Error for V1NetworkMessageDecoderError {}
+impl std::error::Error for V1NetworkMessageDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self.0 {
+ V1NetworkMessageDecoderErrorInner::Header => None,
+ V1NetworkMessageDecoderErrorInner::PayloadTooLarge => None,
+ V1NetworkMessageDecoderErrorInner::Payload => None,
+ }
+ }
+}
impl Encodable for V2NetworkMessage {
fn consensus_encode<W: Write + ?Sized>(&self, writer: &mut W) -> Result<usize, io::Error> {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.