From befe431304da827da672e5d110958f0f3736a69b Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Tue, 28 Apr 2026 17:29:12 +0700 Subject: [PATCH] feat(client): Reject empty open_timeouts configuration with dedicated error --- crates/irtt-client/src/client.rs | 12 ++++++++++++ crates/irtt-client/src/error.rs | 2 ++ crates/irtt-client/src/socket.rs | 3 +++ 3 files changed, 17 insertions(+) diff --git a/crates/irtt-client/src/client.rs b/crates/irtt-client/src/client.rs index b503bee..2ef68f5 100644 --- a/crates/irtt-client/src/client.rs +++ b/crates/irtt-client/src/client.rs @@ -791,4 +791,16 @@ mod tests { Err(ClientError::OpenTimeoutTooSmall { .. }) )); } + + #[test] + fn empty_open_timeouts_is_rejected() { + let config = ClientConfig { + open_timeouts: vec![], + ..ClientConfig::default() + }; + assert!(matches!( + Client::connect(config), + Err(ClientError::NoOpenTimeouts) + )); + } } diff --git a/crates/irtt-client/src/error.rs b/crates/irtt-client/src/error.rs index 483fd62..aaffab9 100644 --- a/crates/irtt-client/src/error.rs +++ b/crates/irtt-client/src/error.rs @@ -17,6 +17,8 @@ pub enum ClientError { timeout: Duration, minimum: Duration, }, + #[error("open_timeouts must not be empty")] + NoOpenTimeouts, #[error("server rejected the open request")] ServerRejected, #[error("unexpected no-test open reply")] diff --git a/crates/irtt-client/src/socket.rs b/crates/irtt-client/src/socket.rs index 34fcda5..a662a09 100644 --- a/crates/irtt-client/src/socket.rs +++ b/crates/irtt-client/src/socket.rs @@ -11,6 +11,9 @@ use crate::{ }; pub(crate) fn validate_open_timeouts(timeouts: &[Duration]) -> Result<(), ClientError> { + if timeouts.is_empty() { + return Err(ClientError::NoOpenTimeouts); + } for timeout in timeouts { if *timeout < MIN_OPEN_TIMEOUT { return Err(ClientError::OpenTimeoutTooSmall {