From 4b5038912a8579e916628b2f40628ec9eba1f276 Mon Sep 17 00:00:00 2001 From: Brandon Pike Date: Sat, 30 Nov 2024 15:31:08 -0800 Subject: [PATCH] Update Other errors to HostUnreachable Rust 1.83 has dropped and with it comes new error kinds! --- src/sim.rs | 2 +- src/top.rs | 6 +----- tests/tcp.rs | 8 ++++---- tests/udp.rs | 8 ++++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/sim.rs b/src/sim.rs index 868550e..3cf6b8a 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -674,7 +674,7 @@ mod test { sim.client("client", async move { // Peers are partitioned. TCP setup should fail. let err = TcpStream::connect("server:1234").await.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::Other); + assert_eq!(err.kind(), io::ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) diff --git a/src/top.rs b/src/top.rs index f810112..12615b4 100644 --- a/src/top.rs +++ b/src/top.rs @@ -243,11 +243,7 @@ impl Topology { link.enqueue_message(&self.config, rand, src, dst, message); Ok(()) } else { - // TODO: `ErrorKind::Other` is incorrect here, but - // `ErrorKind::HostUnreachable` has not been stabilized. - // - // See: https://github.com/rust-lang/rust/issues/86442 - Err(Error::new(ErrorKind::Other, "host unreachable")) + Err(Error::new(ErrorKind::HostUnreachable, "host unreachable")) } } diff --git a/tests/tcp.rs b/tests/tcp.rs index 1238b58..e379aeb 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -45,7 +45,7 @@ fn network_partitions_during_connect() -> Result { turmoil::partition("client", "server"); let err = TcpStream::connect(("server", PORT)).await.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::Other); + assert_eq!(err.kind(), io::ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); turmoil::repair("client", "server"); @@ -220,7 +220,7 @@ fn network_partition_once_connected() -> Result { assert!(timeout(Duration::from_secs(1), s.read_u8()).await.is_err()); let err = s.write_u8(1).await.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::Other); + assert_eq!(err.kind(), io::ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) @@ -232,7 +232,7 @@ fn network_partition_once_connected() -> Result { turmoil::partition("server", "client"); let err = s.write_u8(1).await.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::Other); + assert_eq!(err.kind(), io::ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) @@ -1129,7 +1129,7 @@ fn socket_to_nonexistent_node() -> Result { ); let err = sock.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::Other); + assert_eq!(err.kind(), io::ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) diff --git a/tests/udp.rs b/tests/udp.rs index 9a38311..9f2083a 100644 --- a/tests/udp.rs +++ b/tests/udp.rs @@ -235,7 +235,7 @@ fn network_partition() -> Result { let sock = bind().await?; let err = send_ping(&sock).await.unwrap_err(); - assert_eq!(err.kind(), ErrorKind::Other); + assert_eq!(err.kind(), ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) @@ -562,7 +562,7 @@ fn loopback_localhost_public_v4() -> Result { let bind_addr = SocketAddr::new(bind_addr.ip(), 0); let socket = UdpSocket::bind(bind_addr).await?; let err = socket.send_to(&expected, connect_addr).await.unwrap_err(); - assert_eq!(err.kind(), ErrorKind::Other); + assert_eq!(err.kind(), ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) @@ -614,7 +614,7 @@ fn loopback_localhost_public_v6() -> Result { let bind_addr = SocketAddr::new(bind_addr.ip(), 0); let socket = UdpSocket::bind(bind_addr).await?; let err = socket.send_to(&expected, connect_addr).await.unwrap_err(); - assert_eq!(err.kind(), ErrorKind::Other); + assert_eq!(err.kind(), ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(()) @@ -723,7 +723,7 @@ fn socket_to_nonexistent_node() -> Result { ); let err = send.unwrap_err(); - assert_eq!(err.kind(), ErrorKind::Other); + assert_eq!(err.kind(), ErrorKind::HostUnreachable); assert_eq!(err.to_string(), "host unreachable"); Ok(())