feat(client): add configuration validation and new error types

This commit is contained in:
Nils Andreas Svee committed 2026-04-28 21:55:49 +07:00
1 parent 443040c175
commit 2f5d5744ea
2 files changed
+12

No files matched your search

+10
View File
@@ -40,6 +40,16 @@ pub struct Client {
impl Client { impl Client {
pub fn connect(config: ClientConfig) -> Result<Self, ClientError> { pub fn connect(config: ClientConfig) -> Result<Self, ClientError> {
validate_open_timeouts(&config.open_timeouts)?; validate_open_timeouts(&config.open_timeouts)?;
if config.max_pending_probes == 0 {
return Err(ClientError::InvalidConfig {
reason: "max_pending_probes must be greater than zero".to_owned(),
});
}
if config.probe_timeout == Duration::ZERO {
return Err(ClientError::InvalidConfig {
reason: "probe_timeout must be greater than zero".to_owned(),
});
}
let remote = resolve_remote(&config)?; let remote = resolve_remote(&config)?;
let socket = connect_udp_socket(&config.socket_config, remote)?; let socket = connect_udp_socket(&config.socket_config, remote)?;
let requested = params_from_config(&config)?; let requested = params_from_config(&config)?;
+2
View File
@@ -43,4 +43,6 @@ pub enum ClientError {
DurationOverflow, DurationOverflow,
#[error("pending probe limit exceeded ({limit})")] #[error("pending probe limit exceeded ({limit})")]
PendingLimitExceeded { limit: usize }, PendingLimitExceeded { limit: usize },
#[error("invalid configuration: {reason}")]
InvalidConfig { reason: String },
} }