feat(client): add configuration validation and new error types
This commit is contained in:
1 parent
265618b97e
commit
cdf41f2a82
2 files changed
+12
No files matched your search
@@ -40,6 +40,16 @@ pub struct Client {
|
||||
impl Client {
|
||||
pub fn connect(config: ClientConfig) -> Result<Self, ClientError> {
|
||||
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 socket = connect_udp_socket(&config.socket_config, remote)?;
|
||||
let requested = params_from_config(&config)?;
|
||||
|
||||
@@ -43,4 +43,6 @@ pub enum ClientError {
|
||||
DurationOverflow,
|
||||
#[error("pending probe limit exceeded ({limit})")]
|
||||
PendingLimitExceeded { limit: usize },
|
||||
#[error("invalid configuration: {reason}")]
|
||||
InvalidConfig { reason: String },
|
||||
}
|
||||
Reference in new issue
Block a user