Explorar o código

[net] Tor dialers: return error instead of panic

Refactor the Tor Dialers to return an error instead of panicking via
unwrap(). In any case, we don't expect this to happen because new
dialers are instantiated using a macro that ensures that endpoints have
valid hosts and ports.
y %!s(int64=2) %!d(string=hai) anos
pai
achega
e4eb6754dd
Modificáronse 1 ficheiros con 4 adicións e 4 borrados
  1. 4 4
      src/net/transport/mod.rs

+ 4 - 4
src/net/transport/mod.rs

@@ -214,8 +214,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::Tor(dialer) => {
-                let host = self.endpoint.host_str().unwrap();
-                let port = self.endpoint.port().unwrap();
+                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
+                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors
@@ -233,8 +233,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::TorTls(dialer) => {
-                let host = self.endpoint.host_str().unwrap();
-                let port = self.endpoint.port().unwrap();
+                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
+                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors