From f66363787ba10877beaad1a868abd956c47663a9 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Wed, 9 Oct 2024 11:02:45 +0700 Subject: [PATCH] fix wrong unwrap --- src/quic.rs | 2 +- src/service/alias_service.rs | 2 +- src/stream.rs | 10 +++++----- src/tests.rs | 6 +++--- src/tests/visualization.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/quic.rs b/src/quic.rs index d6cf79c..e617328 100644 --- a/src/quic.rs +++ b/src/quic.rs @@ -16,7 +16,7 @@ fn configure_server(priv_key: PrivatePkcs8KeyDer<'static>, cert: CertificateDer< let cert_chain = vec![cert]; let mut server_config = ServerConfig::with_single_cert(cert_chain, priv_key.into())?; - let transport_config = Arc::get_mut(&mut server_config.transport).unwrap(); + let transport_config = Arc::get_mut(&mut server_config.transport).expect("should get mut"); transport_config.max_concurrent_uni_streams(0_u8.into()); transport_config.max_idle_timeout(Some(Duration::from_secs(5).try_into().expect("Should config timeout"))); diff --git a/src/service/alias_service.rs b/src/service/alias_service.rs index 15ce2ca..2cadbe4 100644 --- a/src/service/alias_service.rs +++ b/src/service/alias_service.rs @@ -398,7 +398,7 @@ mod test { Self { internal: AliasServiceInternal { local: HashMap::new(), - cache: LruCache::new(LRU_CACHE_SIZE.try_into().unwrap()), + cache: LruCache::new(LRU_CACHE_SIZE.try_into().expect("should create NoneZeroUsize")), find_reqs: HashMap::new(), outs: VecDeque::new(), }, diff --git a/src/stream.rs b/src/stream.rs index 3bfc548..813119a 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -94,15 +94,15 @@ impl Decoder for BincodeCodec { pub async fn wait_object(reader: &mut R) -> anyhow::Result { let mut len_buf = [0; 2]; let mut data_buf = [0; MAX_SIZE]; - reader.read_exact(&mut len_buf).await.unwrap(); + reader.read_exact(&mut len_buf).await?; let handshake_len = u16::from_be_bytes([len_buf[0], len_buf[1]]) as usize; if handshake_len > data_buf.len() { return Err(anyhow!("packet to big {} vs {MAX_SIZE}", data_buf.len())); } - reader.read_exact(&mut data_buf[0..handshake_len]).await.unwrap(); + reader.read_exact(&mut data_buf[0..handshake_len]).await?; - Ok(bincode::deserialize(&data_buf[0..handshake_len]).unwrap()) + Ok(bincode::deserialize(&data_buf[0..handshake_len])?) } pub async fn write_object(writer: &mut W, object: &O) -> anyhow::Result<()> { @@ -112,7 +112,7 @@ pub async fn write_object) -> let cert = CertificateDer::from(DEFAULT_CLUSTER_CERT.to_vec()); let addr = { - let socket = UdpSocket::bind("127.0.0.1:0").unwrap(); - socket.local_addr().unwrap() + let socket = UdpSocket::bind("127.0.0.1:0").expect("should bind"); + socket.local_addr().expect("should get local") }; let peer_id = PeerId::from(peer_id); ( @@ -34,7 +34,7 @@ async fn create_node(advertise: bool, peer_id: u64, seeds: Vec) -> seeds, }) .await - .unwrap(), + .expect("should create network"), (peer_id, addr.into()).into(), ) } diff --git a/src/tests/visualization.rs b/src/tests/visualization.rs index 8a0ef94..efddf6b 100644 --- a/src/tests/visualization.rs +++ b/src/tests/visualization.rs @@ -20,8 +20,8 @@ async fn discovery_new_node() { tokio::time::sleep(Duration::from_secs(1)).await; let mut events = vec![ - tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.unwrap().unwrap(), - tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.unwrap().unwrap(), + tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.expect("").expect(""), + tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.expect("").expect(""), ]; for event in events.iter_mut() {